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


Java BasicDBObject类代码示例

本文整理汇总了Java中com.mongodb.BasicDBObject的典型用法代码示例。如果您正苦于以下问题:Java BasicDBObject类的具体用法?Java BasicDBObject怎么用?Java BasicDBObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BasicDBObject类属于com.mongodb包,在下文中一共展示了BasicDBObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAppInfoByAppNames

import com.mongodb.BasicDBObject; //导入依赖的package包/类
@Override
public List<ApplicationDTO> getAppInfoByAppNames(List<String> names) {

    Aggregation aggregation = newAggregation(
        match(Criteria.where("appname").in(names).and("timestamp").exists(true)),
        sort(new Sort(DESC, "timestamp")),
        project("appname", "platform", "starrating",
                    "timestamp", "comment", "authorName","url"),
        group("appname", "platform")
            .push(new BasicDBObject("author", "$authorName")
                .append("rate", "$starrating" )
                .append("timestamp", "$timestamp")
                .append("comment", "$comment")
                .append("url", "$url")
            ).as("reviews"),
        project("appname", "platform")
            .and("reviews").slice(8, 0)
    );

    //Convert the aggregation result into a List
    AggregationResults<ApplicationDTO> groupResults
            = mongoTemplate.aggregate(aggregation, Review.class, ApplicationDTO.class);

    return groupResults.getMappedResults();
}
 
开发者ID:BBVA,项目名称:mirrorgate,代码行数:26,代码来源:ReviewRepositoryImpl.java

示例2: getNextId

import com.mongodb.BasicDBObject; //导入依赖的package包/类
public int getNextId(GridFS destDatabase) {
	DBCollection countersCollection = destDatabase.getDB().getCollection("counters");

	DBObject record = countersCollection.findOne(new BasicDBObject("_id", "package"));
	if (record == null) {
		BasicDBObject dbObject = new BasicDBObject("_id", "package");
		dbObject.append("seq", 0);
		countersCollection.insert(dbObject);
		record = dbObject;
	}
	int oldID = (int) record.get("seq");
	int newID = oldID + 1;
	record.put("seq", newID);
	countersCollection.update(new BasicDBObject("_id", "package"), record);
	
	return newID;
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:18,代码来源:DataManager.java

示例3: buildFilters

import com.mongodb.BasicDBObject; //导入依赖的package包/类
private void buildFilters(BasicDBObject pushdownFilters,
    Map<String, List<BasicDBObject>> mergedFilters) {
  for (Entry<String, List<BasicDBObject>> entry : mergedFilters.entrySet()) {
    List<BasicDBObject> list = entry.getValue();
    if (list.size() == 1) {
      this.filters.putAll(list.get(0).toMap());
    } else {
      BasicDBObject andQueryFilter = new BasicDBObject();
      andQueryFilter.put("$and", list);
      this.filters.putAll(andQueryFilter.toMap());
    }
  }
  if (pushdownFilters != null && !pushdownFilters.toMap().isEmpty()) {
    if (!mergedFilters.isEmpty()) {
      this.filters = MongoUtils.andFilterAtIndex(this.filters,
          pushdownFilters);
    } else {
      this.filters = pushdownFilters;
    }
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:22,代码来源:MongoRecordReader.java

示例4: testDeleteGroup

import com.mongodb.BasicDBObject; //导入依赖的package包/类
/**
 * Add a new group object to the database. Call DELETE using the id of the new mongo object.
 * Verify that the group no longer exists in the database
 *
 * @throws GeneralSecurityException
 */
@Test
public void testDeleteGroup() throws IOException, GeneralSecurityException {
  System.out.println("\nStarting testDeleteGroup");

  // Create group in database
  Group group = new Group(null, "testGroup", new String[] {"12345"});
  BasicDBObject dbGroup = group.getDBObject(false);
  db.getCollection(Group.DB_COLLECTION_NAME).insert(dbGroup);
  group.setId(dbGroup.getObjectId(Group.DB_ID).toString());

  ObjectId groupId = dbGroup.getObjectId(Group.DB_ID);
  // Make DELETE call with group id
  String url = groupServiceURL + "/" + groupId;
  makeConnection("DELETE", url, null, 200);

  // Verify that the group no longer exists in mongo
  BasicDBObject groupAfterDelete = (BasicDBObject) db.getCollection("groups").findOne(groupId);
  assertNull("The group still exists after DELETE was called", groupAfterDelete);
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:26,代码来源:GroupResourceTest.java

示例5: getAgentByAgentId

import com.mongodb.BasicDBObject; //导入依赖的package包/类
public AgentFull getAgentByAgentId(String agentId){
	System.out.println("Searching host in DB with agentId = " + agentId);
	logger.info("Searching host in DB with agentId = " + agentId);
	AgentFull agent = null;
	BasicDBObject query = new BasicDBObject();
       query.put("agentId", agentId);

       DBCursor cursor = getAgentTable().find(query);
       if (cursor.hasNext()){
       	agent = new AgentFull();
       	agent.setAgentId((String) cursor.next().get("agentId"));
       	agent.setHost((String) cursor.curr().get("host"));
       	agent.setMonitored((boolean) cursor.curr().get("monitored"));
       	agent.setLogstashIp((String) cursor.curr().get("logstashIp"));
       	agent.setLogstashPort((String) cursor.curr().get("logstashPort"));
       	logger.info("Host finded in DB with agentId = " + agentId + " with ipAddress " + agent.getHost());
       	System.out.println("Host finded in DB with agentId = " + agentId + " with ipAddress " + agent.getHost());
       }
       else {
       	logger.info("Host doesn't exists in DB with agentId = " + agentId);
       	System.out.println("Host doesn't exists in DB with agentId = " + agentId);
       	return null;
       }		
	return agent;
}
 
开发者ID:elastest,项目名称:elastest-instrumentation-manager,代码行数:26,代码来源:AgentRepository.java

示例6: checkEncryptedSubdocument

import com.mongodb.BasicDBObject; //导入依赖的package包/类
@Test
public void checkEncryptedSubdocument() {
    MyBean bean = new MyBean();
    MySubBean subBean = new MySubBean("sky is blue", "   earth is round");
    bean.secretSubBean = subBean;
    mongoTemplate.save(bean);

    MyBean fromDb = mongoTemplate.findOne(query(where("_id").is(bean.id)), MyBean.class);

    assertThat(fromDb.secretSubBean.nonSensitiveData, is(bean.secretSubBean.nonSensitiveData));
    assertThat(fromDb.secretSubBean.secretString, is(bean.secretSubBean.secretString));

    DBObject fromMongo = mongoTemplate.getCollection(MyBean.MONGO_MYBEAN).find(new BasicDBObject("_id", new ObjectId(bean.id))).next();

    int expectedLength = 12
            + MySubBean.MONGO_NONSENSITIVEDATA.length() + subBean.secretString.length() + 7
            + MySubBean.MONGO_SECRETSTRING.length() + subBean.nonSensitiveData.length() + 7;

    assertCryptLength(fromMongo.get(MyBean.MONGO_SECRETSUBBEAN), expectedLength);
}
 
开发者ID:bolcom,项目名称:spring-data-mongodb-encrypt,代码行数:21,代码来源:EncryptSystemTest.java

示例7: getDBObject

import com.mongodb.BasicDBObject; //导入依赖的package包/类
/** Return an object suitable to create a new user in MongoDB. */
public BasicDBObject getDBObject(boolean includeId) {
  BasicDBObject user = new BasicDBObject();
  if (includeId) {
    user.append(DB_ID, new ObjectId(id));
  }
  user.append(JSON_KEY_USER_FIRST_NAME, firstName);
  user.append(JSON_KEY_USER_LAST_NAME, lastName);
  user.append(JSON_KEY_USER_NAME, userName);
  user.append(JSON_KEY_USER_TWITTER_HANDLE, twitterHandle);
  user.append(JSON_KEY_USER_WISH_LIST_LINK, wishListLink);
  user.append(JSON_KEY_USER_PASSWORD_HASH, passwordHash);
  user.append(JSON_KEY_USER_PASSWORD_SALT, passwordSalt);
  user.append(JSON_KEY_USER_TWITTER_LOGIN, isTwitterLogin);

  return user;
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:18,代码来源:User.java

示例8: mongoSerialise

import com.mongodb.BasicDBObject; //导入依赖的package包/类
@Override
public BasicDBObject mongoSerialise() {
    BasicDBObject dbObject = new BasicDBObject();

    dbObject.put("i", getObjectId());
    dbObject.put("t", ID);
    dbObject.put("x", getX());
    dbObject.put("y", getY());
    dbObject.put("direction", getDirection().ordinal());
    dbObject.put("heldItem", heldItem);
    dbObject.put("hp", hp);
    dbObject.put("action", lastAction.ordinal());
    dbObject.put("holo", hologram);
    dbObject.put("holoStr", hologramString);
    dbObject.put("holoMode", lastHologramMode.ordinal());
    dbObject.put("holoC", hologramColor);
    dbObject.put("energy", energy);

    if (parent != null) {
        dbObject.put("parent", parent.getUsername()); //Only used client-side for now
    }

    return dbObject;
}
 
开发者ID:simon987,项目名称:Much-Assembly-Required,代码行数:25,代码来源:Cubot.java

示例9: toDbObject

import com.mongodb.BasicDBObject; //导入依赖的package包/类
public static DBObject toDbObject(NameValues nameValues)
{
    final BasicDBObject basicDBObject = new BasicDBObject();
    nameValues.forEach(new NameValues.Foreach()
    {

        @Override
        public boolean forEach(String name, Object value)
        {
            basicDBObject.append(name, value);
            return true;
        }
    });

    return basicDBObject;
}
 
开发者ID:gzxishan,项目名称:OftenPorter,代码行数:17,代码来源:Util.java

示例10: convert

import com.mongodb.BasicDBObject; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public VirtualObject convert(DBObject source) {
	Integer rid = (Integer) source.get("rid");
	Integer classId = (Integer) source.get("eClassId");
	Long oid = (Long) source.get("oid");
	Object featuresObject = source.get("features");
	
	EClass eclass = platformService.getEClassForCid(classId.shortValue());
	
	VirtualObject result = new VirtualObject(rid, classId.shortValue(), oid, eclass);
	
	if (featuresObject instanceof BasicDBObject) {
		Map map = (Map) featuresObject;
		processFeatures(map, result);
	}
	return result;
}
 
开发者ID:shenan4321,项目名称:BIMplatform,代码行数:19,代码来源:VirtualObjectReadConverter.java

示例11: saveEntry

import com.mongodb.BasicDBObject; //导入依赖的package包/类
/**
 * Saves an entry to file
 * @param entry
 * @param dbName usually scrapig
 * @return true if success
 */
public static boolean saveEntry(DBEntry entry, String dbName){

    if(entry == null || !entry.isValid())
        return false;

    Logger log = Logger.getLogger(DAO.class);

    MongoDatabase db = MongoDB.INSTANCE.getDatabase(dbName);

    String collectionName = getCollectionName(entry);


    MongoCollection collection = db.getCollection(collectionName,BasicDBObject.class);

    try {
        collection.insertOne(entry);
        return true;
    }
    catch (MongoWriteException ex){
        if (ex.getCode() != 11000) // Ignore errors about duplicates
            log.error(ex.getError().getMessage());
        return false;
    }

}
 
开发者ID:gidim,项目名称:Babler,代码行数:32,代码来源:DAO.java

示例12: countAction

import com.mongodb.BasicDBObject; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private List<Map> countAction(DataStoreMsg msg, Map queryparmes, MongoCollection<Document> collection) {

    BasicDBObject query = new BasicDBObject();// output

    Map findparmes = (Map) queryparmes.get(DataStoreProtocol.WHERE);
    QueryStrategy qry = new QueryStrategy();
    Map express = new LinkedHashMap();
    express.put(DataStoreProtocol.FIND, findparmes);
    qry.concretProcessor(DataStoreProtocol.FIND, express, query);

    // for (Object qobj : query.keySet()) {
    // log.info(this, "shell in package:" + qobj.toString() + ":" + query.get(qobj));
    // }

    log.info(this, "MongoDBDataStore countAction toJson : " + query.toJson());

    long countN = collection.count(query);
    Map<String, Object> item = new LinkedHashMap<String, Object>();
    item.put(DataStoreProtocol.COUNT, countN);
    List<Map> res = new ArrayList<Map>();
    res.add(item);

    return res;

}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:27,代码来源:MongoDBDataStore.java

示例13: concretProcessor

import com.mongodb.BasicDBObject; //导入依赖的package包/类
@Override
public void concretProcessor(Object key, Map elemData, List<Bson> list) {

    if (null == key && null == elemData) {
        list.add(new BasicDBObject("$project",
                new BasicDBObject("_id", 0).append(DataStoreProtocol.RESULT, "$" + DataStoreProtocol.RESULT)));
    }
    else {
        Document filterBson = new Document();
        filterBson.append("_id", 0);
        String fileds = (String) elemData.get(DataStoreProtocol.FIELDS);
        if (!StringHelper.isEmpty(fileds)) {
            String[] filters = fileds.split(";");
            for (String filter : filters) {
                filterBson.append(filter, 1);
            }
        }

        list.add(new BasicDBObject("$project", filterBson));
    }
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:22,代码来源:MongodbAggregateStrategy.java

示例14: getAgentConfigurationByAgentId

import com.mongodb.BasicDBObject; //导入依赖的package包/类
public AgentConfigurationDatabase getAgentConfigurationByAgentId(String agentId){
	System.out.println("Searching agent cfg in DB with agentId = " + agentId);
	logger.info("Searching host in DB with agentId = " + agentId);
	BasicDBObject query = new BasicDBObject();
       query.put("agentId", agentId);

       DBCursor cursor = getAgentConfigurationTable().find(query);
       if (cursor.hasNext()){
       	logger.info("Agent cfg exists in DB with agentId = " + agentId);
       	return this.toAgentCfgDbObject(cursor.next());
       }
       else {
       	logger.info("Agent cfg doesn't exists in DB with agentId = " + agentId);
       	System.out.println("Agent cfg doesn't exists in DB with agentId = " + agentId);
       	return null;
       }		
}
 
开发者ID:elastest,项目名称:elastest-instrumentation-manager,代码行数:18,代码来源:AgentConfigurationRepository.java

示例15: existHost

import com.mongodb.BasicDBObject; //导入依赖的package包/类
public boolean existHost(String ipAddress){		
	logger.info("Verifying if host with ipAddress = " + ipAddress + " exists");
	System.out.println("Verifying if host with ipAddress = " + ipAddress + " exists");
       BasicDBObject query = new BasicDBObject();
       query.put("host", ipAddress);

       DBCursor cursor = getAgentTable().find(query);
       if (cursor.hasNext()){
       	logger.info("Host with ipAddress = " + ipAddress + " exists");
       	System.out.println("Host with ipAddress = " + ipAddress + " exists");
       	return true;
       }
       else {
       	logger.info("Not exists any host with ipAddress = " + ipAddress);
       	System.out.println("Not exists any host with ipAddress = " + ipAddress);
       	return false;
       }        
}
 
开发者ID:elastest,项目名称:elastest-instrumentation-manager,代码行数:19,代码来源:AgentRepository.java


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