当前位置: 首页>>代码示例>>Java>>正文


Java DB.getCollection方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:20,代码来源:SynonymsGenerator.java

示例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());
}
 
开发者ID:karlkyck,项目名称:spring-boot-completablefuture,代码行数:23,代码来源:InitialSetupMigration.java

示例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);
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:11,代码来源:InitialSetupMigration.java

示例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());
	}
}
 
开发者ID:acardoco,项目名称:crauler_ISI,代码行数:34,代码来源:MongoFunctions.java

示例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();
		}
}
 
开发者ID:Arquisoft,项目名称:Trivial5b,代码行数:25,代码来源:Mongo.java

示例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;
	}
}
 
开发者ID:orionhealth,项目名称:XBDD,代码行数:20,代码来源:Presence.java

示例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());
	
}
 
开发者ID:dynamo2,项目名称:tianma,代码行数:26,代码来源:SimpleTest.java

示例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;
	}
}
 
开发者ID:orionhealth,项目名称:XBDD,代码行数:19,代码来源:Presence.java

示例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);
}
 
开发者ID:orionhealth,项目名称:XBDD,代码行数:24,代码来源:TagView.java

示例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;
	}
}
 
开发者ID:orionhealth,项目名称:XBDD,代码行数:23,代码来源:Presence.java

示例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");
}
 
开发者ID:elastest,项目名称:elastest-instrumentation-manager,代码行数:8,代码来源:AgentConfigurationRepository.java

示例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");
}
 
开发者ID:elastest,项目名称:elastest-instrumentation-manager,代码行数:8,代码来源:AgentRepository.java

示例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());
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:13,代码来源:InitialSetupMigration.java

示例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()
    );
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:35,代码来源:InitialSetupMigration.java

示例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());
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:13,代码来源:InitialSetupMigration.java


注:本文中的com.mongodb.DB.getCollection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。