本文整理了Java中com.mongodb.BasicDBObject.<init>()
方法的一些代码示例,展示了BasicDBObject.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BasicDBObject.<init>()
方法的具体详情如下:
包路径:com.mongodb.BasicDBObject
类名称:BasicDBObject
方法名:<init>
[英]Creates an empty object.
[中]
代码示例来源:origin: stackoverflow.com
BasicDBObject update = new BasicDBObject().append("$push", new BasicDBObject().append("values", dboVital));
update = update.append("$set", new BasicDBObject().append("endTime", time));
collection.update( new BasicDBObject().append("_id", pageId), update, true, false);
代码示例来源:origin: Graylog2/graylog2-server
@Override
public long totalExtractorCount() {
final DBObject query = new BasicDBObject(InputImpl.EMBEDDED_EXTRACTORS, new BasicDBObject("$exists", true));
long extractorsCount = 0;
try (DBCursor inputs = dbCollection.find(query, new BasicDBObject(InputImpl.EMBEDDED_EXTRACTORS, 1))) {
for (DBObject input : inputs) {
final BasicDBList extractors = (BasicDBList) input.get(InputImpl.EMBEDDED_EXTRACTORS);
extractorsCount += extractors.size();
}
}
return extractorsCount;
}
代码示例来源:origin: stackoverflow.com
BasicDBObject q = new BasicDBObject();
q.put("name", java.util.regex.Pattern.compile(m));
dbc.find(q);
代码示例来源:origin: Graylog2/graylog2-server
@Inject
public IndexFieldTypesService(MongoConnection mongoConnection,
MongoJackObjectMapperProvider objectMapperProvider) {
this.db = JacksonDBCollection.wrap(mongoConnection.getDatabase().getCollection("index_field_types"),
IndexFieldTypesDTO.class,
ObjectId.class,
objectMapperProvider.get());
this.db.createIndex(new BasicDBObject(ImmutableMap.of(
IndexFieldTypesDTO.FIELD_INDEX_NAME, 1,
IndexFieldTypesDTO.FIELD_INDEX_SET_ID, 1
)), new BasicDBObject("unique", true));
this.db.createIndex(new BasicDBObject(IndexFieldTypesDTO.FIELD_INDEX_NAME, 1), new BasicDBObject("unique", true));
this.db.createIndex(new BasicDBObject(FIELDS_FIELD_NAMES, 1));
}
代码示例来源:origin: Graylog2/graylog2-server
public BasicDBList getList(String key) {
DBCollection coll = getCollection();
DBObject query = new BasicDBObject();
query.put("key", key);
DBObject result = coll.findOne(query);
return (BasicDBList) result.get("value");
}
代码示例来源:origin: stackoverflow.com
DBObject document1 = new BasicDBObject();
document1.put("name", "Kiran");
document1.put("age", 20);
DBObject document2 = new BasicDBObject();
document2.put("name", "John");
List<DBObject> documents = new ArrayList<>();
documents.add(document1);
documents.add(document2);
collection.insert(documents);
代码示例来源:origin: MorphiaOrg/morphia
@Test
public void testQueryUnmappedData() {
getMorphia().map(Class1.class);
getDs().ensureIndexes(true);
getDs().getDB().getCollection("user").save(
new BasicDBObject()
.append("@class", Class1.class.getName())
.append("value1", "foo")
.append("someMap", new BasicDBObject("someKey", "value")));
Query<Class1> query = getDs().createQuery(Class1.class);
query.disableValidation().criteria("someMap.someKey").equal("value");
Class1 retrievedValue = query.find(new FindOptions().limit(1)).next();
Assert.assertNotNull(retrievedValue);
Assert.assertEquals("foo", retrievedValue.value1);
}
代码示例来源:origin: org.mongodb/mongo-java-driver
private byte[] getChunk(final int chunkNumber) {
if (fs == null) {
throw new IllegalStateException("No GridFS instance defined!");
}
DBObject chunk = fs.getChunksCollection().findOne(new BasicDBObject("files_id", id).append("n", chunkNumber));
if (chunk == null) {
throw new MongoException("Can't find a chunk! file id: " + id + " chunk: " + chunkNumber);
}
return (byte[]) chunk.get("data");
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public Map<String, Node> allActive(Node.Type type) {
Map<String, Node> nodes = Maps.newHashMap();
BasicDBObject query = new BasicDBObject();
query.put("last_seen", new BasicDBObject("$gte", Tools.getUTCTimestamp() - pingTimeout));
query.put("type", type.toString());
for (DBObject obj : query(NodeImpl.class, query)) {
Node node = new NodeImpl((ObjectId) obj.get("_id"), obj.toMap());
String nodeId = (String) obj.get("node_id");
nodes.put(nodeId, node);
}
return nodes;
}
代码示例来源:origin: MorphiaOrg/morphia
@Override
public AggregationPipeline group(final String id, final Group... groupings) {
DBObject group = new BasicDBObject();
group.put("_id", id != null ? "$" + id : null);
for (Group grouping : groupings) {
group.putAll(toDBObject(grouping));
}
stages.add(new BasicDBObject("$group", group));
return this;
}
代码示例来源:origin: org.mongodb/mongo-java-driver
/**
* Deals with encoding database references.
*
* @param name the name of the field in the document
* @param ref the database reference object
*/
protected void putDBRef(final String name, final DBRef ref) {
BasicDBObject dbRefDocument = new BasicDBObject("$ref", ref.getCollectionName()).append("$id", ref.getId());
if (ref.getDatabaseName() != null) {
dbRefDocument.put("$db", ref.getDatabaseName());
}
putObject(name, dbRefDocument);
}
代码示例来源: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
Mongo mongo = PowerMockito.mock(Mongo.class);
DB db = PowerMockito.mock(DB.class);
DBCollection dbCollection = PowerMockito.mock(DBCollection.class);
PowerMockito.when(mongo.getDB("foo")).thenReturn(db);
PowerMockito.when(db.getCollection("bar")).thenReturn(dbCollection);
MyService svc = new MyService(mongo); // Use some kind of dependency injection
svc.getObjectById(1);
PowerMockito.verify(dbCollection).findOne(new BasicDBObject("_id", 1));
代码示例来源: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: Graylog2/graylog2-server
@Override
public Input findForThisNodeOrGlobal(String nodeId, String id) throws NotFoundException {
final List<BasicDBObject> forThisNodeOrGlobal = ImmutableList.of(
new BasicDBObject(MessageInput.FIELD_NODE_ID, nodeId),
new BasicDBObject(MessageInput.FIELD_GLOBAL, true));
final List<BasicDBObject> query = ImmutableList.of(
new BasicDBObject(InputImpl.FIELD_ID, new ObjectId(id)),
new BasicDBObject("$or", forThisNodeOrGlobal));
final DBObject o = findOne(InputImpl.class, new BasicDBObject("$and", query));
return new InputImpl((ObjectId) o.get(InputImpl.FIELD_ID), o.toMap());
}
代码示例来源:origin: Graylog2/graylog2-server
public boolean getBoolean(String key) {
DBCollection coll = getCollection();
DBObject query = new BasicDBObject();
query.put("key", key);
DBObject result = coll.findOne(query);
if (result == null) {
return false;
}
if (result.get("value").equals(true)) {
return true;
}
return false;
}
代码示例来源:origin: MorphiaOrg/morphia
/**
* Sets the sort value for the update
*
* @param field the field to sort by
* @param direction the direction of the sort
* @return this
*/
public PushOptions sort(final String field, final int direction) {
if (sort != null) {
throw new IllegalStateException("sortDocument can not be set if sort already is");
}
if (sortDocument == null) {
sortDocument = new BasicDBObject();
}
sortDocument.put(field, direction);
return this;
}
代码示例来源:origin: Graylog2/graylog2-server
ContentPackPersistenceService(final JacksonDBCollection<ContentPack, ObjectId> dbCollection) {
this.dbCollection = dbCollection;
try {
dbCollection.createIndex(new BasicDBObject(Identified.FIELD_META_ID, 1).append(Revisioned.FIELD_META_REVISION, 1), new BasicDBObject("unique", true));
} catch (DuplicateKeyException e) {
// Ignore - this can happen if this runs before the migration of old content packs
}
}
代码示例来源:origin: MorphiaOrg/morphia
@Test
@SuppressWarnings("deprecation")
public void testCommentsShowUpInLogsOld() {
getDs().save(asList(new Pic("pic1"), new Pic("pic2"), new Pic("pic3"), new Pic("pic4")));
getDb().command(new BasicDBObject("profile", 2));
String expectedComment = "test comment";
toList(getDs().find(Pic.class).comment(expectedComment).find());
DBCollection profileCollection = getDb().getCollection("system.profile");
assertNotEquals(0, profileCollection.count());
DBObject profileRecord = profileCollection.findOne(new BasicDBObject("op", "query")
.append("ns", getDs().getCollection(Pic.class).getFullName()));
assertEquals(profileRecord.toString(), expectedComment, getCommentFromProfileRecord(profileRecord));
turnOffProfilingAndDropProfileCollection();
}
代码示例来源:origin: MorphiaOrg/morphia
private void checkIndex(final DBObject dbObject) {
assertTrue((Boolean) dbObject.get("background"));
assertTrue((Boolean) dbObject.get("unique"));
assertTrue((Boolean) dbObject.get("sparse"));
assertEquals(42L, dbObject.get("expireAfterSeconds"));
assertEquals(new BasicDBObject("name", 1).append("text", -1), dbObject.get("key"));
}
内容来源于网络,如有侵权,请联系作者删除!