本文整理汇总了Java中com.mongodb.DB.getCollection方法的典型用法代码示例。如果您正苦于以下问题:Java DB.getCollection方法的具体用法?Java DB.getCollection怎么用?Java DB.getCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.DB
的用法示例。
在下文中一共展示了DB.getCollection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateFile
import com.mongodb.DB; //导入方法依赖的package包/类
public void generateFile(String filename) {
DB db = MongoHelper.mongoMerchantDB();
DBCollection col = db.getCollection(COLLECTION_SYNONYMS);
DBCursor cursor = col.find();
try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(filename, true)))) {
while (cursor.hasNext()) {
DBObject doc = cursor.next();
String word = doc.get(FIELD_KEY_WORLD) != null ? doc.get(FIELD_KEY_WORLD).toString() : null;
String synonyms = doc.get(FIELD_KEY_WORLD) != null
? StringUtils.join((BasicDBList) doc.get(FIELD_KEY_SYNONYMS), ",") : null;
if (word != null && synonyms != null) {
out.println(createLine(word, synonyms));
}
}
} catch (IOException e) {
throw new RuntimeException("IOException: Current db cursor with id: " + cursor.curr().get("_id"), e);
}
}
示例2: addUsers
import com.mongodb.DB; //导入方法依赖的package包/类
@ChangeSet(order = "01",
author = "developer",
id = "01-addUsers")
public void addUsers(final DB db) {
final DBCollection userCollection = db.getCollection(User.COLLECTION_NAME);
userCollection.insert(BasicDBObjectBuilder
.start()
.add(FIELD_NAME_ID, new ObjectId("590f86d92449343841cc2c3f"))
.add(User.FIELD_NAME_FIRST_NAME, "User")
.add(User.FIELD_NAME_LAST_NAME, "One")
.add(User.FIELD_NAME_EMAIL, "[email protected]")
.get());
userCollection.insert(BasicDBObjectBuilder
.start()
.add(FIELD_NAME_ID, new ObjectId("590f86d92449343841cc2c40"))
.add(User.FIELD_NAME_FIRST_NAME, "User")
.add(User.FIELD_NAME_LAST_NAME, "Two")
.add(User.FIELD_NAME_EMAIL, "[email protected]")
.get());
}
示例3: addSocialUserConnection
import com.mongodb.DB; //导入方法依赖的package包/类
@ChangeSet(order = "03", author = "initiator", id = "03-addSocialUserConnection")
public void addSocialUserConnection(DB db) {
DBCollection socialUserConnectionCollection = db.getCollection("jhi_social_user_connection");
socialUserConnectionCollection.createIndex(BasicDBObjectBuilder
.start("user_id", 1)
.add("provider_id", 1)
.add("provider_user_id", 1)
.get(),
"user-prov-provusr-idx", true);
}
示例4: calcularLocalizaciones
import com.mongodb.DB; //导入方法依赖的package包/类
/**
* Map reduce.
*
* @param mongoOperation
* the mongo operation
* @param a
* the a
* @param b
* the b
* @param c
* the c
* @param d
* the d
* @throws UnknownHostException
*/
static void calcularLocalizaciones() throws UnknownHostException {
String map = "function () { emit(this.localizacion, {count: 1}); }";
String reduce = " function(key, values) { var result = 0; values.forEach(function(value){ result++ }); "
+ "return result; }";
MongoClient mongoClient = new MongoClient("localhost", 27017);
DB db = mongoClient.getDB("craulerdb");
DBCollection ofertas = db.getCollection("ofertas");
MapReduceCommand cmd = new MapReduceCommand(ofertas, map, reduce, null, MapReduceCommand.OutputType.INLINE,
null);
MapReduceOutput out = ofertas.mapReduce(cmd);
for (DBObject o : out.results()) {
System.out.println(o.toString());
}
}
示例5: main
import com.mongodb.DB; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
MongoClient mongoClient = new MongoClient("localhost", 27017);
DB db = mongoClient.getDB("mydb");
DBCollection coll = db.getCollection("questionsCollection");
mongoClient.setWriteConcern(WriteConcern.JOURNALED);
GIFTParser p = new GIFTParser();
BasicDBObject doc = null;
for (Question q : p.parserGIFT("Data/questionsGIFT")) {
doc = new BasicDBObject("category", q.getCategory())
.append("question", q.getText())
.append("correctanswer", q.getCorrectAnswer())
.append("wrongAnswers",q.getWrongAnswers());
coll.insert(doc);
}
DBCursor cursor = coll.find();
try {
while(cursor.hasNext()) {
System.out.println(cursor.next());
}
} finally {
cursor.close();
}
}
示例6: deletePresence
import com.mongodb.DB; //导入方法依赖的package包/类
@DELETE
@Path("/{product}/{major}.{minor}.{servicePack}/{build}/{featureId}")
public DBObject deletePresence(@BeanParam final Coordinates coordinates, @PathParam("featureId") final String featureId,
@Context final HttpServletRequest req) {
try {
final DB db = this.client.getDB("bdd");
final DBCollection collection = db.getCollection("presence");
final BasicDBObject query = new BasicDBObject("coordinates", coordinates.getObject(Field.PRODUCT, Field.VERSION, Field.BUILD).append(
"featureId", featureId))
.append("_id", coordinates.getProduct() + "/" + coordinates.getVersionString() + "/" + coordinates.getBuild() + "/" + featureId);
collection.update(query, new BasicDBObject("$unset", new BasicDBObject("users." + req.getRemoteUser(), 1)), true, false);
final DBObject newPresence = collection.findOne(query);
newPresence.put("currentUser", req.getRemoteUser());
return newPresence;
} catch (final Throwable th) {
th.printStackTrace();
return null;
}
}
示例7: main
import com.mongodb.DB; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
BASE64Decoder de = new BASE64Decoder();
byte[] result = de.decodeBuffer(data);
InputStream in = new ByteArrayInputStream(result);
ZipInputStream zip = new ZipInputStream(in);
ZipEntry entry = zip.getNextEntry();
BufferedReader reader = new BufferedReader(new InputStreamReader(zip));
while(reader.ready()) {
System.out.println(reader.readLine());
}
MongoClient mongoClient = new MongoClient();
DB db = mongoClient.getDB("mydb");
DBCollection coll = db.getCollection("goods");
BasicDBObject doc = new BasicDBObject("name", "MongoDB")
.append("type", "database")
.append("count", 1)
.append("info", new BasicDBObject("x", 203).append("y", 102));
coll.insert(doc);
System.out.println(coll.findOne());
}
示例8: getPresencesForBuild
import com.mongodb.DB; //导入方法依赖的package包/类
@GET
@Path("/{product}/{major}.{minor}.{servicePack}/{build}")
public DBObject getPresencesForBuild(@BeanParam final Coordinates coordinates) {
try {
final DB db = this.client.getDB("bdd");
final DBCollection collection = db.getCollection("presence");
final BasicDBObject query = coordinates.getQueryObject(Field.PRODUCT, Field.VERSION, Field.BUILD);
final BasicDBList presencesForBuild = new BasicDBList();
final DBCursor cursor = collection.find(query);
while (cursor.hasNext()) {
presencesForBuild.add(cursor.next());
}
return presencesForBuild;
} catch (final Throwable th) {
th.printStackTrace();
return null;
}
}
示例9: getFeatureTagIndexForReport
import com.mongodb.DB; //导入方法依赖的package包/类
@GET
@Produces("application/json")
@Path("/featureTagIndex/{product}/{major}.{minor}.{servicePack}/{build}")
public BasicDBList getFeatureTagIndexForReport(@BeanParam final Coordinates coordinates,
@QueryParam("searchText") final String searchText, @QueryParam("viewPassed") final Integer viewPassed,
@QueryParam("viewFailed") final Integer viewFailed,
@QueryParam("viewUndefined") final Integer viewUndefined, @QueryParam("viewSkipped") final Integer viewSkipped,
@QueryParam("start") final String start) {
final DB db = this.client.getDB("bdd");
final DBCollection featuresCollection = db.getCollection("features");
final BasicDBObject query = QueryBuilder.getInstance().buildFilterQuery(coordinates, searchText, viewPassed,
viewFailed, viewUndefined, viewSkipped, start);
query.append("$and", QueryBuilder.getInstance().buildHasTagsQuery());
final DBCursor results = featuresCollection.find(query,
new BasicDBObject("tags", 1).append("elements.tags", 1).append("name", 1).append("calculatedStatus", 1)
.append("id", 1).append("elements.steps", 1).append("elements.name", 1).append("elements.id", 1));
return getTagList(results);
}
示例10: addPresence
import com.mongodb.DB; //导入方法依赖的package包/类
@POST
@Path("/{product}/{major}.{minor}.{servicePack}/{build}/{featureId}")
public DBObject addPresence(@BeanParam final Coordinates coordinates, @PathParam("featureId") final String featureId,
@Context final HttpServletRequest req) {
try {
final DB db = this.client.getDB("bdd");
final DBCollection collection = db.getCollection("presence");
final BasicDBObject query = new BasicDBObject("coordinates", coordinates.getObject(Field.PRODUCT, Field.VERSION, Field.BUILD).append(
"featureId", featureId))
.append("_id", coordinates.getProduct() + "/" + coordinates.getVersionString() + "/" + coordinates.getBuild() + "/" + featureId);
final Date now = Calendar.getInstance().getTime();
collection.update(query,
new BasicDBObject("$set", new BasicDBObject("users." + req.getRemoteUser(), now).append("lastUpdated", now)), true,
false);
final DBObject newPresence = collection.findOne(query);
newPresence.put("currentUser", req.getRemoteUser());
return newPresence;
} catch (final Throwable th) {
th.printStackTrace();
return null;
}
}
示例11: AgentConfigurationRepository
import com.mongodb.DB; //导入方法依赖的package包/类
public AgentConfigurationRepository(){
MongoClient mongoClient = new MongoClient(
Properties.getValue(Dictionary.PROPERTY_MONGODB_HOST),
27017);
DB db = mongoClient.getDB("eim");
collection = db.getCollection("agentConfiguration");
}
示例12: AgentRepository
import com.mongodb.DB; //导入方法依赖的package包/类
public AgentRepository(){
MongoClient mongoClient = new MongoClient(
Properties.getValue(Dictionary.PROPERTY_MONGODB_HOST),
27017);
DB db = mongoClient.getDB("eim");
collection = db.getCollection("agent");
}
示例13: addAuthorities
import com.mongodb.DB; //导入方法依赖的package包/类
@ChangeSet(order = "01", author = "initiator", id = "01-addAuthorities")
public void addAuthorities(DB db) {
DBCollection authorityCollection = db.getCollection("jhi_authority");
authorityCollection.insert(
BasicDBObjectBuilder.start()
.add("_id", "ROLE_ADMIN")
.get());
authorityCollection.insert(
BasicDBObjectBuilder.start()
.add("_id", "ROLE_USER")
.get());
}
示例14: addUsers
import com.mongodb.DB; //导入方法依赖的package包/类
@ChangeSet(order = "02", author = "initiator", id = "02-addUsers")
public void addUsers(DB db) {
DBCollection usersCollection = db.getCollection("jhi_user");
usersCollection.createIndex("login");
usersCollection.createIndex("email");
usersCollection.insert(BasicDBObjectBuilder.start()
.add("_id", "user-0")
.add("login", "system")
.add("password", "*************")
.add("first_name", "")
.add("last_name", "System")
.add("email", "[email protected]")
.add("activated", "true")
.add("lang_key", "en")
.add("created_by", "system")
.add("created_date", new Date())
.add("authorities", authoritiesAdminAndUser)
.get()
);
usersCollection.insert(BasicDBObjectBuilder.start()
.add("_id", "user-1")
.add("login", "anonymousUser")
.add("password", "*************")
.add("first_name", "Anonymous")
.add("last_name", "User")
.add("email", "[email protected]")
.add("activated", "true")
.add("lang_key", "en")
.add("created_by", "system")
.add("created_date", new Date())
.add("authorities", new Map[]{})
.get()
);
}
示例15: addAuthorities2
import com.mongodb.DB; //导入方法依赖的package包/类
@ChangeSet(order = "04", author = "user", id = "04-addAuthorities-2")
public void addAuthorities2(DB db) {
DBCollection authorityCollection = db.getCollection("jhi_authority");
authorityCollection.insert(
BasicDBObjectBuilder.start()
.add("_id", "ROLE_MANAGER")
.get());
authorityCollection.insert(
BasicDBObjectBuilder.start()
.add("_id", "ROLE_SUPPORT")
.get());
}