com.mongodb.DBObject Java Examples
The following examples show how to use
com.mongodb.DBObject.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InternalValidator.java From scava with Eclipse Public License 2.0 | 8 votes |
private Map<String, Float> readDistanceScores(String startingObject, Set<String> others) { Map<String, Float> result = new HashMap<String, Float>(); Query query = new org.springframework.data.mongodb.core.query.Query(); query.addCriteria(Criteria.where("type.name").is(_SIMILARITY_METHOD).orOperator( Criteria.where("fromArtifact.$id").is(new ObjectId(startingObject)), Criteria.where("toArtifact.$id").is(new ObjectId(startingObject)))); DBCollection dbCollection = mongoTemplate.getCollection("relation"); DBCursor cursor = dbCollection.find(query.getQueryObject()); List<DBObject> list = cursor.toArray(); for (DBObject dbObject : list) { String toArtifact = ((DBRef) dbObject.get("toArtifact")).getId().toString(); String fromArtifact = ((DBRef) dbObject.get("fromArtifact")).getId().toString(); double value = ((double) dbObject.get("value")); if (toArtifact.equals(startingObject)) { if (others.contains(fromArtifact)) result.put(fromArtifact, (float) (1 - value)); } else if (others.contains(toArtifact)) result.put(toArtifact, (float) (1 - value)); } return result; }
Example #2
Source File: CreateIdListener.java From moserp with Apache License 2.0 | 7 votes |
@Override public void onApplicationEvent(MongoMappingEvent<?> event) { if (!(event instanceof BeforeSaveEvent)) { return; } if (!IdentifiableEntity.class.isAssignableFrom(event.getSource().getClass())) { return; } IdentifiableEntity source = (IdentifiableEntity) event.getSource(); if (source.getId() != null) { return; } DBObject dbObject = event.getDBObject(); String id = sequenceService.getNextIt(event.getSource().getClass()); source.setId(id); dbObject.put("_id", id); }
Example #3
Source File: MongoAccessLogValve.java From tomcat-mongo-access-log with Apache License 2.0 | 6 votes |
@Override public void addElement(StringBuilder buf, DBObject result, Date date, Request request, Response response, long time) { // Don't need to flush since trigger for log message is after the // response has been committed long length = response.getBytesWritten(false); if (length <= 0) { // Protect against nulls and unexpected types as these values // may be set by untrusted applications Object start = request.getAttribute( Globals.SENDFILE_FILE_START_ATTR); if (start instanceof Long) { Object end = request.getAttribute( Globals.SENDFILE_FILE_END_ATTR); if (end instanceof Long) { length = ((Long) end).longValue() - ((Long) start).longValue(); } } } if (length <= 0 && conversion) { result.put("bytesSent", '-'); } else { result.put("bytesSent", length); } }
Example #4
Source File: GuildManager.java From gameserver with Apache License 2.0 | 6 votes |
/** * Search the guild by given regex name * @param guildName * @return */ public final Collection<Guild> searchGuild(String guildName, int startPos, int count) { DBObject query = createDBObject(); DBObject cond =createDBObject("$regex", guildName); cond.put("$options", "i"); query.put(GUILDTITLE_NAME, cond); List<DBObject> dbObjs = null; if ( count > 0 ) { dbObjs = MongoDBUtil.queryAllFromMongo( query, databaseName, namespace, COLL_NAME, null, sorts, startPos, count); } else { dbObjs = MongoDBUtil.queryAllFromMongo( query, databaseName, namespace, COLL_NAME, null, sorts); } ArrayList<Guild> list = new ArrayList<Guild>(); for ( DBObject dbObj : dbObjs ) { Guild guild = (Guild)MongoDBUtil.constructObject(dbObj); list.add(guild); } return list; }
Example #5
Source File: MongoUserManager.java From gameserver with Apache License 2.0 | 6 votes |
/** * Delete an user from database by his/her name, including all the bag and * relation data. * * @param roleName * @return */ @Override public void removeUserByRoleName(String roleName) { DBObject query = createDBObject(LOGIN_ROLENAME, roleName); DBObject field = createDBObject(_ID, 1); DBObject userObj = MongoDBUtil.queryFromMongo(query, databaseName, namespace, USER_COLL_NAME, field); if ( userObj == null ) { return; } byte[] bytes = (byte[])userObj.get(_ID); if ( bytes != null ) { UserId userId = UserId.fromBytes(bytes); this.removeUser(userId); } }
Example #6
Source File: MongoCommander.java From secure-data-service with Apache License 2.0 | 6 votes |
/** * get list of the shards * @param dbConn * @return */ private static List<String> getShards(DB dbConn) { List<String> shards = new ArrayList<String>(); DBObject listShardsCmd = new BasicDBObject("listShards", 1); CommandResult res = dbConn.command(listShardsCmd); if (!res.ok()) { LOG.error("Error getting shards for {}: {}", dbConn, res.getErrorMessage()); } BasicDBList listShards = (BasicDBList) res.get("shards"); //Only get shards for sharding mongo if (listShards != null) { ListIterator<Object> iter = listShards.listIterator(); while (iter.hasNext()) { BasicDBObject shard = (BasicDBObject) iter.next(); shards.add(shard.getString(ID)); } } return shards; }
Example #7
Source File: MongoUtilTest.java From gameserver with Apache License 2.0 | 6 votes |
@Test public void testRemoveDocument() { DBObject query = MongoDBUtil.createDBObject(); int count = 10; for ( int i=0; i<count; i++ ) { DBObject dbObject = new BasicDBObject(); dbObject.put("_id", i); dbObject.put("name", "value"+i); MongoDBUtil.saveToMongo(dbObject, dbObject, testDB, null, "mongoutil", true); } List<DBObject> list = MongoDBUtil.queryAllFromMongo(query, testDB, null, "mongoutil", null); assertTrue(list.size()>0); MongoDBUtil.removeDocument(testDB, null, "mongoutil", null); list = MongoDBUtil.queryAllFromMongo(query, testDB, null, "mongoutil", null); assertEquals(0, list.size()); }
Example #8
Source File: PongoFactory.java From scava with Eclipse Public License 2.0 | 6 votes |
public Pongo resolveReference(Object ref) { if (ref instanceof DBRef) { DBRef dbRef = (DBRef) ref; String fullyQualifiedId = dbRef.getDB().getName() + "." + dbRef.getRef() + "." + dbRef.getId().toString(); Pongo pongo = (Pongo) cache.get(fullyQualifiedId); if (pongo == null) { DBObject dbObject = dbRef.getDB().getCollection(dbRef.getRef()).findOne(new BasicDBObject("_id", dbRef.getId())); if (dbObject != null) { pongo = createPongo(dbObject, dbRef.getDB().getCollection(dbRef.getRef())); } } return pongo; } else { return null; } }
Example #9
Source File: MongoDbDeltaStoreUtil.java From incubator-retired-wave with Apache License 2.0 | 6 votes |
public static DBObject serialize(TransformedWaveletDelta transformedWaveletDelta) { BasicDBObject mongoTransformedWaveletDelta = new BasicDBObject(); mongoTransformedWaveletDelta.append(FIELD_AUTHOR, serialize(transformedWaveletDelta.getAuthor())); mongoTransformedWaveletDelta.append(FIELD_RESULTINGVERSION, serialize(transformedWaveletDelta.getResultingVersion())); mongoTransformedWaveletDelta.append(FIELD_APPLICATIONTIMESTAMP, transformedWaveletDelta.getApplicationTimestamp()); mongoTransformedWaveletDelta.append(FIELD_APPLIEDATVERSION, transformedWaveletDelta.getAppliedAtVersion()); BasicDBList mongoWaveletOperations = new BasicDBList(); for (WaveletOperation op : transformedWaveletDelta) { mongoWaveletOperations.add(serialize(op)); } mongoTransformedWaveletDelta.append(FIELD_OPS, mongoWaveletOperations); return mongoTransformedWaveletDelta; }
Example #10
Source File: MongodbInputDiscoverFieldsImplTest.java From pentaho-mongodb-plugin with Apache License 2.0 | 6 votes |
@Test public void testPipelineQueryIsLimited() throws KettleException, MongoDbException { setupPerform(); String query = "{$sort : 1}"; // Setup DBObjects collection List<DBObject> dbObjects = new ArrayList<DBObject>(); DBObject firstOp = (DBObject) JSON.parse( query ); DBObject[] remainder = { new BasicDBObject( "$limit", NUM_DOCS_TO_SAMPLE ) }; dbObjects.add( firstOp ); Collections.addAll( dbObjects, remainder ); AggregationOptions options = AggregationOptions.builder().build(); //when( MongodbInputDiscoverFieldsImpl.jsonPipelineToDBObjectList( query ) ).thenReturn( dbObjects ); when( collection.aggregate( anyList(), any( AggregationOptions.class ) ) ) .thenReturn( cursor ); discoverFields.discoverFields( new MongoProperties.Builder(), "mydb", "mycollection", query, "", true, NUM_DOCS_TO_SAMPLE, inputMeta ); verify( collection ).aggregate( anyList(), any( AggregationOptions.class ) ); }
Example #11
Source File: RemoveInvalidDocs_Script.java From bluima with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { MongoConnection mongo = new MongoConnection(MONGO_FT_CONNECTION); File ns_pmIds = new File( "/Users/richarde/Desktop/BBP_experiments/27_cleanup_pm-ft_in_mongo/CheckFtAgainstAbstracts.log.s.cut.uniq"); int[] readInts = LineReader.intsFrom(new FileInputStream(ns_pmIds)); for (int pmid : readInts) { DBObject r = new BasicDBObject("_id", pmid + ""); mongo.coll.remove(r); Progress.tick(); } System.err.println("done :-)"); }
Example #12
Source File: PlantsCatalog.java From cqrs-sample with MIT License | 6 votes |
public DBObject execute(){ BasicDBObject plant = new BasicDBObject("code", getPlantData().getCode()); DBObject thePlant = coll.findOne(plant); if (thePlant==null){ coll.save(plant); System.out.println("New Plant has been saved into PlantCatalog DB"); return plant; } System.out.println("in execute di PlantsCatalog: description->" + getPlantData().getDescription()); System.out.println("in execute di PlantsCatalog: price->" + getPlantData().getPrice()); coll.findAndModify(plant, thePlant); return thePlant; }
Example #13
Source File: MongoEntityTest.java From secure-data-service with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void testCreateAggregate() { Map<String, Object> body = new HashMap<String, Object>(); Map<String, Object> aggregate = new HashMap<String, Object>(); Map<String, Object> assessments = new HashMap<String, Object>(); Map<String, Object> mathTest = new HashMap<String, Object>(); Map<String, Integer> highestEver = new HashMap<String, Integer>(); highestEver.put("E", 15); highestEver.put("2", 20); mathTest.put("HighestEver", highestEver); assessments.put("ACT", mathTest); aggregate.put("assessments", assessments); DBObject dbObject = new BasicDBObjectBuilder().add("_id", "42").add("body", body) .add("aggregations", aggregate).get(); CalculatedData<Map<String, Integer>> data = MongoEntity.fromDBObject(dbObject).getAggregates(); assertEquals(Arrays.asList(new CalculatedDatum<Map<String, Integer>>("assessments", "HighestEver", "ACT", "aggregate", highestEver)), data.getCalculatedValues()); }
Example #14
Source File: InternalValidator.java From scava with Eclipse Public License 2.0 | 6 votes |
private Map<String, Float> readDistanceScores(String object) { Map<String, Float> result = new HashMap<String, Float>(); Query query = new org.springframework.data.mongodb.core.query.Query(); query.addCriteria(Criteria.where("type.name").is(_SIMILARITY_METHOD).orOperator( Criteria.where("fromArtifact.$id").is(new ObjectId(object)), Criteria.where("toArtifact.$id").is(new ObjectId(object)))); DBCollection dbCollection = mongoTemplate.getCollection("relation"); DBCursor cursor = dbCollection.find(query.getQueryObject()); List<DBObject> list = cursor.toArray(); for (DBObject dbObject : list) { String toArtifact = ((DBRef) dbObject.get("toArtifact")).getId().toString(); String fromArtifact = ((DBRef) dbObject.get("fromArtifact")).getId().toString(); double value = ((double) dbObject.get("value")); if (toArtifact.equals(object)) result.put(fromArtifact, (float) (1 - value)); else result.put(toArtifact, (float) (1 - value)); } return result; }
Example #15
Source File: MongoDB.java From act with GNU General Public License v3.0 | 6 votes |
public DBIterator getIdCursorForFakeChemicals() { DBObject fakeRegex = new BasicDBObject(); DBObject abstractInchi = new BasicDBObject(); fakeRegex.put(ChemicalKeywords.INCHI$.MODULE$.toString(), new BasicDBObject(MongoKeywords.REGEX$.MODULE$.toString(), "^InChI=/FAKE")); abstractInchi.put(ChemicalKeywords.INCHI$.MODULE$.toString(), new BasicDBObject(MongoKeywords.REGEX$.MODULE$.toString(), "^InChI=.*R.*")); BasicDBList conditionList = new BasicDBList(); conditionList.add(fakeRegex); conditionList.add(abstractInchi); BasicDBObject conditions = new BasicDBObject(MongoKeywords.OR$.MODULE$.toString(), conditionList); return getIteratorOverChemicals(conditions, new BasicDBObject(ChemicalKeywords.ID$.MODULE$.toString(), true)); }
Example #16
Source File: SampleValidation.java From hvdf with Apache License 2.0 | 6 votes |
public void validate(DBObject sample){ if(sample != null && sample.containsField(TARGET_FIELD_KEY)){ int xValue = (Integer)sample.get(TARGET_FIELD_KEY); // Throw a standard exception if an illegal value is encountered if(xValue == illegalValue){ throw new ServiceException("Illegal value for field_x", SampleError.INVALID_SAMPLE).set(TARGET_FIELD_KEY, xValue); } // Change the value to clip to a configured maximum if(xValue > maxValue){ sample.put(TARGET_FIELD_KEY, maxValue); } } else{ // The field does not exist throw new ServiceException("Sample missing value for field_x", SampleError.INVALID_SAMPLE); } }
Example #17
Source File: QueryBuilderTest.java From XBDD with Apache License 2.0 | 5 votes |
@Test public void buildTestQueryWithEmptySearch() { final String[] searchCategories = { "name", "age" }; final List<String> searchKeys = new ArrayList<>(); searchKeys.add(""); final BasicDBObject searchQuery = this.queryBuilder.getSearchQuery(searchKeys, this.coordinates, searchCategories); @SuppressWarnings("unchecked") final List<DBObject> queryResults = (ArrayList<DBObject>) searchQuery.get("$or"); assertTrue(queryResults.isEmpty()); }
Example #18
Source File: MongoRepositoryItem.java From kurento-java with Apache License 2.0 | 5 votes |
private void putMetadataInGridFS(boolean save) { DBObject metadataDBO = new BasicDBObject(); for (Entry<String, String> entry : metadata.entrySet()) { metadataDBO.put(entry.getKey(), entry.getValue()); } dbFile.setMetaData(metadataDBO); if (save) { dbFile.save(); } }
Example #19
Source File: Search.java From XBDD with Apache License 2.0 | 5 votes |
@GET @Path("/{product}/{major}.{minor}.{servicePack}/{build}") @Produces(MediaType.APPLICATION_JSON) public Response getSearchResults(@BeanParam final Coordinates coordinates, @QueryParam("keywords") final String keyword) { final String[] searchCategories = { "name", "description", "tags.name", "elements.name", "elements.description", "elements.steps.name", "elements.tags.name" }; final List<String> searchWords = Arrays.asList(keyword.split("\\s+")); final DBCollection collection = this.mongoLegacyDb.getCollection("features"); final List<DBObject> searchResults = new ArrayList<>(); final QueryBuilder queryBuilder = QueryBuilder.getInstance(); final DBCursor results = collection.find(queryBuilder.getSearchQuery(searchWords, coordinates, searchCategories)); while (results.hasNext()) { final DBObject doc = results.next(); searchResults.add(doc); } searchResults.sort(new DBObjectComparator(searchWords)); while (searchResults.size() > SEARCH_LIMIT) { searchResults.remove(searchResults.size() - 1); } final BasicDBList basicDBList = new BasicDBList(); basicDBList.addAll(searchResults); return Response.ok(SerializerUtil.serialise(basicDBList)).build(); }
Example #20
Source File: MongoDbStore.java From swellrt with Apache License 2.0 | 5 votes |
private DBObject robotToObject(RobotAccountData account) { return new BasicDBObject() .append(ROBOT_URL_FIELD, account.getUrl()) .append(ROBOT_SECRET_FIELD, account.getConsumerSecret()) .append(ROBOT_CAPABILITIES_FIELD, capabilitiesToObject(account.getCapabilities())) .append(ROBOT_VERIFIED_FIELD, account.isVerified()); }
Example #21
Source File: BuguUpdater.java From bugu-mongo with Apache License 2.0 | 5 votes |
private Object checkSingleValue(String key, Object value){ Class<T> clazz = dao.getEntityClass(); Object result = value; if(value instanceof BuguEntity){ BuguEntity be = (BuguEntity)value; result = ReferenceUtil.toDbReference(clazz, key, be.getClass(), be.getId()); }else if(!(value instanceof DBObject) && FieldsCache.getInstance().isEmbedField(clazz, key)){ result = MapperUtil.toDBObject(value); } return result; }
Example #22
Source File: MongoDbOutputTest.java From pentaho-mongodb-plugin with Apache License 2.0 | 5 votes |
@Test public void testTopLevelObjectStructureTwoLevelNested() throws Exception { List<MongoDbOutputMeta.MongoField> paths = new ArrayList<MongoDbOutputMeta.MongoField>( 2 ); MongoDbOutputMeta.MongoField mf = new MongoDbOutputMeta.MongoField(); mf.m_incomingFieldName = "field1"; mf.m_mongoDocPath = "nestedDoc.secondNested"; mf.m_useIncomingFieldNameAsMongoFieldName = true; paths.add( mf ); mf = new MongoDbOutputMeta.MongoField(); mf.m_incomingFieldName = "field2"; mf.m_mongoDocPath = "nestedDoc"; mf.m_useIncomingFieldNameAsMongoFieldName = true; paths.add( mf ); RowMetaInterface rmi = new RowMeta(); rmi.addValueMeta( new ValueMetaString( "field1" ) ); rmi.addValueMeta( new ValueMetaInteger( "field2" ) ); Object[] row = new Object[ 2 ]; row[ 0 ] = "value1"; row[ 1 ] = 12L; VariableSpace vs = new Variables(); for ( MongoDbOutputMeta.MongoField f : paths ) { f.init( vs ); } DBObject result = kettleRowToMongo( paths, rmi, row, MongoDbOutputData.MongoTopLevel.RECORD, false ); assertEquals( JSON.serialize( result ), "{ \"nestedDoc\" : { \"secondNested\" : { \"field1\" : \"value1\"} , \"field2\" : 12}}" ); }
Example #23
Source File: TaskAwardTableModel.java From gameserver with Apache License 2.0 | 5 votes |
@Override public void insertRow(Object row) { Object rowObj = row; if ( row instanceof DBObject ) { rowObj = MongoUtil.constructObject((DBObject)row); } if ( rowObj instanceof Award ) { isDataChanged = true; this.rewards.add((Award)rowObj); this.reload(); this.fireTableDataChanged(); } }
Example #24
Source File: QueryBuilderFilterQueryTest.java From XBDD with Apache License 2.0 | 5 votes |
@Test public void tagSearchFilterQuery() { final Coordinates co = new Coordinates(); co.setBuild("test"); co.setMajor(1); co.setMinor(1); co.setProduct("test"); co.setServicePack(1); final DBObject expected = BasicDBObject .parse("{ 'coordinates.product' : 'test' , 'coordinates.major' : 1 , 'coordinates.minor' : 1 , 'coordinates.servicePack' : 1 , 'coordinates.build' : 'test' , '$and' : [ { 'tags.name' : { '$regex' : '.*@this.*' , '$options' : 'i'}} , { 'name' : { '$regex' : '.*is.*' , '$options' : 'i'}} , { 'name' : { '$regex' : '.*a.*' , '$options' : 'i'}} , { 'name' : { '$regex' : '.*test.*' , '$options' : 'i'}} , { 'name' : { '$regex' : '.*tag.*' , '$options' : 'i'}} , { 'name' : { '$regex' : '.*filter.*' , '$options' : 'i'}} , { 'name' : { '$regex' : '.*string.*' , '$options' : 'i'}}]}"); assertEquals(QueryBuilder.getInstance().buildFilterQuery(co, "@this is a test tag filter string", 0, 0, 0, 0, null), expected); }
Example #25
Source File: MongoUserManager.java From gameserver with Apache License 2.0 | 5 votes |
/** * When challenge with a friend, record the win/lose record time with him/her * @param user * @param friendRoleName * @param winning * @return */ @Override public Map<RelationType, Collection<People>> saveFriendWinOrLose(User user, User friend, boolean winning) { DBObject setObj = createDBObject(); DBObject unsetObj = createDBObject(); String friendUserName = friend.getUsername(); Map<RelationType, Collection<People>> peopleMap = new HashMap<RelationType, Collection<People>>(); for ( RelationType type : RelationType.values() ) { Relation relation = user.getRelation(type); ArrayList<People> peopleList = new ArrayList<People>(); if ( relation != null ) { People people = relation.findPeopleByUserName(friend.getUsername()); if ( people != null ) { logger.debug("update win/lose of friend {}. relation:{}", friendUserName, type); people.setBasicUser(friend); if ( winning ) { people.setWin(people.getWin()+1); setObj.put(concat(type.tag(), DOT, friendUserName, DOT, "win"), 1); } else { people.setLose(people.getLose()+1); setObj.put(concat(type.tag(), DOT, friendUserName, DOT, "lose"), 1); } peopleList.add(people); relation.modifyPeople(people); } } peopleMap.put(type, peopleList); } UserId userId = user.get_id(); // relObj.put(_ID, userId.getInternal()); DBObject query = createDBObject(_ID, userId.getInternal()); DBObject relObj = createDBObject(); relObj.put(OP_SET, setObj); MongoDBUtil.saveToMongo(query, relObj, databaseName, namespace, REL_COLL_NAME, isSafeWrite); return peopleMap; }
Example #26
Source File: BetweenMongoCollectionReader.java From bluima with Apache License 2.0 | 5 votes |
protected void initQuery(MongoConnection conn) throws IOException { checkArgument(btw.length == 2, "PARAM_BETWEEN should be length 2, " + btw); checkArgument(btw[0] < btw[1], "PARAM_BETWEEN[0] should be < PARAM_BETWEEN[1], " + btw); cur = conn.coll.find( (DBObject) JSON.parse(// "{ \"" + PM_ID + "\": {\"$gt\": " + btw[0] + ", \"$lt\": " + btw[1] + " } }"))// .batchSize(1000); }
Example #27
Source File: MongoDbDeltaStoreUtil.java From swellrt with Apache License 2.0 | 5 votes |
public static TransformedWaveletDelta deserializeTransformedWaveletDelta(DBObject dbObject) throws PersistenceException { ParticipantId author = deserializeParicipantId((DBObject) dbObject.get(FIELD_AUTHOR)); HashedVersion resultingVersion = deserializeHashedVersion((DBObject) dbObject.get(FIELD_RESULTINGVERSION)); long applicationTimestamp = (Long) dbObject.get(FIELD_APPLICATIONTIMESTAMP); BasicDBList dbOps = (BasicDBList) dbObject.get(FIELD_OPS); ImmutableList.Builder<WaveletOperation> operations = ImmutableList.builder(); int numOperations = dbOps.size(); // Code analog to ProtoDeltaStoreDataSerializer.deserialize for (int i = 0; i < numOperations; i++) { WaveletOperationContext context; if (i == numOperations - 1) { context = new WaveletOperationContext(author, applicationTimestamp, 1, resultingVersion); } else { context = new WaveletOperationContext(author, applicationTimestamp, 1); } operations.add(deserializeWaveletOperation((DBObject) dbOps.get(i), context)); } return new TransformedWaveletDelta(author, resultingVersion, applicationTimestamp, operations.build()); }
Example #28
Source File: CollectDataFromOneM2MJobService.java From SDA with BSD 2-Clause "Simplified" License | 5 votes |
/** * JSON값을 구함 * @param doc * @throws Exception * @return String */ private String getJson(Object doc) throws Exception { String rtn = ""; if (doc instanceof DBObject) { DBObject docT = (DBObject) doc; rtn = new Gson().toJson(docT); } else if (doc instanceof String) { rtn = new Gson().toJson(doc); } return rtn; }
Example #29
Source File: MongoUserManager.java From gameserver with Apache License 2.0 | 5 votes |
@Override public User queryUserByRoleName(String roleName) { if ( StringUtil.checkNotEmpty(roleName) ) { DBObject query = createDBObject(); query.put(LOGIN_ROLENAME, roleName); DBObject userObj = MongoDBUtil.queryFromMongo(query, databaseName, namespace, USER_COLL_NAME, null); if ( userObj != null ) { User user = constructUserObject(userObj); return user; } } return null; }
Example #30
Source File: MongodbInputDiscoverFieldsImpl.java From pentaho-mongodb-plugin with Apache License 2.0 | 5 votes |
private static Iterator<DBObject> setUpPipelineSample( String query, int numDocsToSample, DBCollection collection ) throws KettleException { query = query + ", {$limit : " + numDocsToSample + "}"; //$NON-NLS-1$ //$NON-NLS-2$ List<DBObject> samplePipe = jsonPipelineToDBObjectList( query ); Cursor cursor = collection.aggregate( samplePipe, AggregationOptions.builder().build() ); return cursor; }