mongodb service is not starting up
On my ubuntu server, just run: sudo rm /var/lib/mongodb/mongod.lock mongod –repair sudo service mongodb start
On my ubuntu server, just run: sudo rm /var/lib/mongodb/mongod.lock mongod –repair sudo service mongodb start
The main purpose of the aggregation framework is to ease the query of a big number of entries and generate a low number of results that hold value to you. As you have said, you can also use multiple find queries, but remember that you can not create new fields with find queries. On the … Read more
You can do… JavaScript (shell): db.getCollectionNames() Node.js: db.listCollections() Non-JavaScript (shell only): show collections The reason I call that non-JavaScript is because: $ mongo prodmongo/app –eval “show collections” MongoDB shell version: 3.2.10 connecting to: prodmongo/app 2016-10-26T19:34:34.886-0400 E QUERY [thread1] SyntaxError: missing ; before statement @(shell eval):1:5 $ mongo prodmongo/app –eval “db.getCollectionNames()” MongoDB shell version: 3.2.10 connecting … Read more
I solved the same problem just last night, this way: > db.test.aggregate({$group:{_id:{$gt:[“$field”, null]}, count:{$sum:1}}}) { “_id” : true, “count” : 2 } { “_id” : false, “count” : 2 } See http://docs.mongodb.org/manual/reference/bson-types/#bson-types-comparison-order for a full explanation of how this works. Added From comment section: To check if the value doesn’t exist or is null use … Read more
You can try below query. Static Imports import static org.springframework.data.mongodb.core.aggregation.Aggregation.*; import static org.springframework.data.mongodb.core.aggregation.ArrayOperators.Filter.filter; import static org.springframework.data.mongodb.core.aggregation.ComparisonOperators.Eq.valueOf; Code Aggregation aggregation = newAggregation( project().and(filter(“parts”) .as(“item”) .by(valueOf( “item.currentState”) .equalToValue( “Estimation Confirmed”))) .as(“parts”); ); List<outputType> results = mongoTemplate.aggregate(aggregation, inputType, outputType)
You can do this with mongo version higher 2.2 the query like this: db.coll.find({ ‘notes.title’: ‘Hello MongoDB’ }, {‘notes.$’: 1}); you can try with $elemMatch like Justin Jenkins
Use $ne — $not should be followed by the standard operator: An examples for $ne, which stands for not equal: use test switched to db test db.test.insert({author : ‘me’, post: “”}) db.test.insert({author : ‘you’, post: “how to query”}) db.test.find({‘post’: {$ne : “”}}) { “_id” : ObjectId(“4f68b1a7768972d396fe2268”), “author” : “you”, “post” : “how to query” } … Read more
The best way to do this is using the aggregation framework. You need to $group your documents by “user” and return the last document for each user using the $last accumulator operator but for this to work, you need a preliminary sorting stage using the $sort aggregation pipeline operator. To sort your documents, you need … Read more
If you are using MongoDB 4.2, you can use aggregation operators in your update statement, like: .findOneAndUpdate({_id: day.id},[{$set:{present:{$eq:[false,”$present”]}}}]); That will set present to true if it is false, and to false if it is any other value.
Your current schema has the marks field data type as string and you need an integer data type for your aggregation framework to work out the sum. On the other hand, you can use MapReduce to calculate the sum since it allows the use of native JavaScript methods like parseInt() on your object properties in … Read more