com.mongodb.BasicDBObject.put()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中com.mongodb.BasicDBObject.put()方法的一些代码示例,展示了BasicDBObject.put()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BasicDBObject.put()方法的具体详情如下:
包路径:com.mongodb.BasicDBObject
类名称:BasicDBObject
方法名:put

BasicDBObject.put介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

BasicDBObject obj = new BasicDBObject();
obj.put("Age", 1);
obj.put("Name", -1);
coll.ensureIndex(obj);

代码示例来源:origin: MorphiaOrg/morphia

@PreLoad
DBObject preLoadWithParamAndReturn(final DBObject dbObj) {
  final BasicDBObject retObj = new BasicDBObject();
  retObj.putAll(dbObj);
  retObj.put("preLoadWithParamAndReturn", true);
  return retObj;
}

代码示例来源:origin: stackoverflow.com

BasicDBObject carrier = new BasicDBObject();
BasicDBObject query = new BasicDBObject();
query.put("YOUR_QUERY_STRING", YOUR_QUERY_VALUE);

BasicDBObject set = new BasicDBObject("$set", carrier);
carrier.put("a", 6);
carrier.put("b", "wx1");        
myColl.updateMany(query, set);

代码示例来源:origin: MorphiaOrg/morphia

private DBObject toDBObject(final Group group) {
  BasicDBObject dbObject = new BasicDBObject();
  if (group.getAccumulator() != null) {
    dbObject.put(group.getName(), group.getAccumulator().toDBObject());
  } else if (group.getProjections() != null) {
    final BasicDBObject projection = new BasicDBObject();
    for (Projection p : group.getProjections()) {
      projection.putAll(toDBObject(p));
    }
    dbObject.put(group.getName(), projection);
  } else if (group.getNested() != null) {
    dbObject.put(group.getName(), toDBObject(group.getNested()));
  } else {
    dbObject.put(group.getName(), group.getSourceField());
  }
  return dbObject;
}

代码示例来源:origin: stackoverflow.com

BasicDBObject q = new BasicDBObject();
q.put("name",  java.util.regex.Pattern.compile(m));
dbc.find(q);

代码示例来源:origin: stackoverflow.com

BasicDBObject dbo = new BasicDBObject();
 dbo.put("name", "first");
 collection.insert(dbo);
 dbo.put("_id", null);
 dbo.put("name", "second");
 dbo.put("otherInfo", new BasicDBObject("text", "sometext"));
 collection.insert(dbo);
 DBObject query = new BasicDBObject("otherInfo.text", new BasicDBObject("$exists", true));
 DBCursor result = collection.find(query);
 System.out.println(result.size());
 System.out.println(result.iterator().next());

代码示例来源:origin: Graylog2/graylog2-server

@Override
public boolean isOnlyMaster(NodeId nodeId) {
  BasicDBObject query = new BasicDBObject();
  query.put("type", Node.Type.SERVER.toString());
  query.put("last_seen", new BasicDBObject("$gte", Tools.getUTCTimestamp() - pingTimeout));
  query.put("node_id", new BasicDBObject("$ne", nodeId.toString()));
  query.put("is_master", true);
  return query(NodeImpl.class, query).size() == 0;
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
  public boolean isAnyMasterPresent() {
    BasicDBObject query = new BasicDBObject();
    query.put("type", Node.Type.SERVER.toString());
    query.put("last_seen", new BasicDBObject("$gte", Tools.getUTCTimestamp() - pingTimeout));
    query.put("is_master", true);

    return query(NodeImpl.class, query).size() > 0;
  }
}

代码示例来源:origin: stackoverflow.com

import org.bson.types.ObjectId;

public DBObject findDocumentById(String id) {
  BasicDBObject query = new BasicDBObject();
  query.put("_id", new ObjectId(id));
  DBObject dbObj = collection.findOne(query);
  return dbObj;
}

代码示例来源:origin: org.mongodb/mongo-java-driver

cmd.put("mapreduce", mapReduce);
cmd.put("map", map);
cmd.put("reduce", reduce);
  cmd.put("verbose", verbose);
BasicDBObject out = new BasicDBObject();
switch (outputType) {
  case INLINE:
    out.put("inline", 1);
    break;
  case REPLACE:
    out.put("replace", outputCollection);
    break;
  case MERGE:
    out.put("merge", outputCollection);
    break;
  case REDUCE:
    out.put("reduce", outputCollection);
    break;
  default:
  out.put("db", outputDB);
cmd.put("out", out);
  cmd.put("query", query);
  cmd.put("finalize", finalize);

代码示例来源:origin: Graylog2/graylog2-server

@Override
public void dropOutdated() {
  BasicDBObject query = new BasicDBObject();
  query.put("last_seen", new BasicDBObject("$lt", Tools.getUTCTimestamp() - pingTimeout));
  destroyAll(NodeImpl.class, query);
}

代码示例来源:origin: org.mongodb/mongo-java-driver

@Override
  public void serialize(final Object obj, final StringBuilder buf) {
    UUID uuid = (UUID) obj;
    BasicDBObject temp = new BasicDBObject();
    temp.put("$uuid", uuid.toString());
    serializer.serialize(temp, buf);
  }
}

代码示例来源:origin: org.mongodb/mongo-java-driver

@Override
public void serialize(final Object obj, final StringBuilder buf) {
  BasicDBObject temp = new BasicDBObject();
  temp.put("$undefined", true);
  serializer.serialize(temp, buf);
}

代码示例来源:origin: org.mongodb/mongo-java-driver

@Override
public void serialize(final Object obj, final StringBuilder buf) {
  BSONTimestamp t = (BSONTimestamp) obj;
  BasicDBObject temp = new BasicDBObject();
  temp.put("t", Integer.valueOf(t.getTime()));
  temp.put("i", Integer.valueOf(t.getInc()));
  BasicDBObject timestampObj = new BasicDBObject();
  timestampObj.put("$timestamp", temp);
  serializer.serialize(timestampObj, buf);
}

代码示例来源:origin: MorphiaOrg/morphia

@Override
  public DBObject toDBObject() {
    BasicDBObject dbObject = new BasicDBObject();
    if (value instanceof List) {
      List<Object> dbValue = new ArrayList<Object>();
      for (Object o : (List) value) {
        if (o instanceof AggregationElement) {
          dbValue.add(((AggregationElement) o).toDBObject());
        } else {
          dbValue.add(o);
        }
      }
      dbObject.put(operation, dbValue);
    } else if (value instanceof AggregationElement) {
      dbObject.put(operation, ((AggregationElement) value).toDBObject());
    } else {
      dbObject.put(operation, value);
    }

    return dbObject;
  }
}

代码示例来源:origin: org.mongodb/mongo-java-driver

@Override
public void serialize(final Object obj, final StringBuilder buf) {
  BSONTimestamp t = (BSONTimestamp) obj;
  BasicDBObject temp = new BasicDBObject();
  temp.put("$ts", Integer.valueOf(t.getTime()));
  temp.put("$inc", Integer.valueOf(t.getInc()));
  serializer.serialize(temp, buf);
}

代码示例来源:origin: org.mongodb/mongo-java-driver

@Override
public void serialize(final Object obj, final StringBuilder buf) {
  CodeWScope c = (CodeWScope) obj;
  BasicDBObject temp = new BasicDBObject();
  temp.put("$code", c.getCode());
  temp.put("$scope", c.getScope());
  serializer.serialize(temp, buf);
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
public boolean fixed(NotificationImpl.Type type, Node node) {
  BasicDBObject qry = new BasicDBObject();
  qry.put(NotificationImpl.FIELD_TYPE, type.toString().toLowerCase(Locale.ENGLISH));
  if (node != null) {
    qry.put(NotificationImpl.FIELD_NODE_ID, node.getNodeId());
  }
  final boolean removed = destroyAll(NotificationImpl.class, qry) > 0;
  if (removed) {
    auditEventSender.success(AuditActor.system(nodeId), SYSTEM_NOTIFICATION_DELETE, Collections.singletonMap("notification_type", type.getDeclaringClass().getCanonicalName()));
  }
  return removed;
}

代码示例来源:origin: org.mongodb/mongo-java-driver

@Override
public void serialize(final Object obj, final StringBuilder buf) {
  DBRef ref = (DBRef) obj;
  BasicDBObject temp = new BasicDBObject();
  temp.put("$ref", ref.getCollectionName());
  temp.put("$id", ref.getId());
  if (ref.getDatabaseName() != null) {
    temp.put("$db", ref.getDatabaseName());
  }
  serializer.serialize(temp, buf);
}

代码示例来源:origin: org.mongodb/mongo-java-driver

@Override
public void serialize(final Object obj, final StringBuilder buf) {
  Code c = (Code) obj;
  BasicDBObject temp = new BasicDBObject();
  temp.put("$code", c.getCode());
  serializer.serialize(temp, buf);
}

相关文章