mongodb-query

Query in Array with dates

独自空忆成欢 提交于 2020-03-16 05:46:38
问题 I'm trying to do a query(In MongoDB) in array("availability") that will return a only hotel that have the element("available") equals 1 and between the dates inside the availability. But the query return all hotels when the correct return is "Mercato Hotel" Query that i have used without success: {city: "Boston", availability: { $elemMatch: {availability: 1, date: {$gte: ISODate("2015-05-02T00:00:00.000+0000")}, date: {$lte: ISODate("2015-05-04T00:00:00.000+0000")}}}} Json in MongoDb: { "_id"

Count no.of instances of string in a field across documents grouped on another field in MongoDB?

和自甴很熟 提交于 2020-03-15 06:40:26
问题 I've got a specific use case and I'm trying to find a way to do it in one aggregation pipeline and preferably without the need to hardcode any data values. I want to group documents based on one property and see a count of values for a particular field within the document. Example data: { "flightNum": "DL1002", "status": "On time", "date": 20191001 }, { "flightNum": "DL1002", "status": "Delayed", "date": 20191002 }, { "flightNum": "DL1002", "status": "On time", "date": 20191003 }, {

Use mongoexport with a --query for ISODate

我的未来我决定 提交于 2020-03-13 06:08:26
问题 I have this query but i´m getting a syntax error: unexpected identifier mongoexport --db ium --collection events \ --query 'db.events.find({'created_at' : { $gte: ISODate("2016-03-01T00:00:00.001Z"), $lte: ISODate("2016-03-29T23:59:59:59.000Z") }, "name" : "UPDATE_SUCCESS"})' \ --out guille1_test.json what can it be wrong? 回答1: You need to use "extended json" in queries with mongoexport. So the way to specify "dates" is with $date instead. And the --query is just the "query string" in JSON

How to set limitation in array object group by count MongoDB

强颜欢笑 提交于 2020-03-04 16:30:49
问题 i want to get retrieve the most data of city, example only city of jakarta and bekasi will be show, because the most data total of count city. and can use how many dynamically limitation. Link example : MongoPlayground Input [ { "_id": ObjectId("5dcbb949e7599115cf1b9441"), "date": "2019-11-13T15:05:28.379Z", "id": NumberInt(166), "location": { "city": "Bekasi", "country": "Indonesia", "district": "Jatimulya", "latitude": -6.266871666666666, "longitude": 107.01972499999998, "province": "Jawa

How can I implement addFields mongoDB query in Java

断了今生、忘了曾经 提交于 2020-02-28 06:28:49
问题 I have found several example at StackOverFlow related to addFields in Aggregation. But no one implemented in Java. db.getCollection('myDocument').aggregate([ {$match : {"metaId.ref.uuid" : "d6112808-1ce1-4545-bd52-cf55bc4ed25e"}}, {$lookup: {from: "simple", localField: "someId.ref.uuid", foreignField: "uuid", as: "simple"}}, {"$unwind": "$simple"}, {"$addFields": { "metaId.ref.name" : "$simple.name" }} ]) I am not able to Implement In Java Correctly:-- Not getting proper procedure

How can I implement addFields mongoDB query in Java

末鹿安然 提交于 2020-02-28 06:28:24
问题 I have found several example at StackOverFlow related to addFields in Aggregation. But no one implemented in Java. db.getCollection('myDocument').aggregate([ {$match : {"metaId.ref.uuid" : "d6112808-1ce1-4545-bd52-cf55bc4ed25e"}}, {$lookup: {from: "simple", localField: "someId.ref.uuid", foreignField: "uuid", as: "simple"}}, {"$unwind": "$simple"}, {"$addFields": { "metaId.ref.name" : "$simple.name" }} ]) I am not able to Implement In Java Correctly:-- Not getting proper procedure

How to convert NumberDecimal to Double in MongoDB shell?

心不动则不痛 提交于 2020-02-25 08:22:29
问题 I have a document with "test" filed as NumberDecimal type { "_id" : ObjectId("5d1a202e476381c30cd995a4"), "test" : NumberDecimal("0.1") } How to convert "test" field from NumberDecimal to Double in mongodb shell? I tried execute db.collection.find({"test": {$exists: true}}).forEach(function (x) { x.test = parseFloat(x.test); db.collection.save(x); }); but don't solve this problem because it return NaN 回答1: The decimal type is not native to JavaScript, so NumberDecimal values in the shell are

Update value in nested array of mongo 3.5

六眼飞鱼酱① 提交于 2020-02-25 06:05:07
问题 I want to make an upsert call to update as well as insert my data in nested array of mongo db. This is my mongo document. { "_id" : "575", "_class" : "com.spyne.sharing.SpyneShareUserProject", "spyneSharePhotoList" : [ { "_id" : "fxLO68XyMR", "spyneShareUsers" : [ { "_id" : "chittaranjan@eventila.com", "selectedByClient" : false }, { "_id" : "chittaranjan@gmail.com", "selectedByClient" : false } ] }, { "_id" : "nVpD0KoQAI", "spyneShareUsers" : [ { "_id" : "chittaranjan@eventila.com",

Update value in nested array of mongo 3.5

前提是你 提交于 2020-02-25 06:04:12
问题 I want to make an upsert call to update as well as insert my data in nested array of mongo db. This is my mongo document. { "_id" : "575", "_class" : "com.spyne.sharing.SpyneShareUserProject", "spyneSharePhotoList" : [ { "_id" : "fxLO68XyMR", "spyneShareUsers" : [ { "_id" : "chittaranjan@eventila.com", "selectedByClient" : false }, { "_id" : "chittaranjan@gmail.com", "selectedByClient" : false } ] }, { "_id" : "nVpD0KoQAI", "spyneShareUsers" : [ { "_id" : "chittaranjan@eventila.com",

Convert Date to String in nested array in mongodb

好久不见. 提交于 2020-02-25 01:05:11
问题 I have a mongodb collection called cases and inside cases I have an array of cases per company object. So the structure is: Inside each case I want to use the createddate (which is a string) and endDate (also string) and convert it to a mongodb date. When I use NoSQLBooster I add the following query: db.cases.aggregate([ { $match: { companyID: 218 }}, { $unwind: "$cases" }, { $match: { 'cases.id': '299' }}, { $addFields: { 'cases.created': new Date('2010-06-21T00:00:00.000'), 'cases.closed':