I have the following document entry:
{
"_id": {
"$oid": "5f0f876df0127d7d1612139c"
},
"stream": [{
"$numberLong": "1594638000000"
}, 8213.9, 8224, 8213.8, 8224, 18.1126896],
"asset": "BTC/EUR",
"timeframe": "5m",
"date": {
"$date": "2020-07-13T11:00:00.000Z"
},
"__v": 0
}
No matter what I have tried, I'm not able to return this specific entry when I search for the date.
I tried:
{"date":{"$date":new Date("2020-07-13T10:55:00.000+00:00")}}
{"date":{"$date":ISODate("2020-07-13T10:55:00.000Z")}}
No success.
The correct query was:
{"date":ISODate("2020-07-13T12:25:00Z")}
Also there is some nasty bug in Compass.
Related
My MongoDB compass document looks like this
{
"_id": "123456789",
"code": "x123",
"title": "cool",
"createdDate":2022-07-06T08:04:52.156+00:00
"expiryDate":2023-12-31T00:00:00.000+00:00
}
I tried to create a mongo DB script in my pipeline to update the "expirydate" field to a specific date value "9999-12-31T00:00:00.000Z" format. My update script looks like this as I am trying to update it via my pipeline. The createdDate field took the current date correctly.
{
"command": "updateOne",
"datasource_name": "Austrailia",
"collection_name": "Sydney",
"query": {
"code": "x123"
},
"options": {
"upsert": true,
},
"update": {
"$currentDate": {
"createdDate": {
"$type": "date"
}
},
"$set": {
"title": "hot",
"expiryDate": {
"$date": "9999-12-31T00:00:00.000"
}
}
}
}
The script is failing as it is throwing errors -
{MongoError: Unknown modifier: expiryDate. Expected a valid modifier}
The dollar ($) prefixed field \'$date\' in \'expiryDate.$date\' is not valid for storage.
What would be the correct query syntax to update the date field "expiryDate" to the value specified above in the same format here?
I am using mongodb compass and i am trying to insert below data, it is giving error. Any help appreceiated.
/**
* Paste one or more documents here
*/
{
"_id": {
"$oid": "621f567ceff392db081a4135"
},
"CompanyID": "620d2d9efc8cec9c94f26284",
"GeoLevelName": "All India",
"IsActive": 1,
"CreatedUser": "string",
"CreateDate": "2022-02-28T14:27:05.757Z",
"LastModifyDate": "2022-02-28T14:27:05.757Z",
"LastModifyUser": "string"
"GeoLevelMain": [{
"GeoLevelID": "621cdce8b876f1ec17b1cec9",
"GeoLevelValue": "Maharastra"
},{
"GeoLevelID": "621cdce8b876f1ec17b1cec9",
"GeoLevelValue": "Maharastra"
}],
"GeographyID": "621cde14b876f1ec17b1cece",
"DBID": "620f658d6dee6848caf53832",
"Division": {
"DivisionID": "6215d68d9e4786b2f7ab80a0",
"DivisionName": "DivisionName"
}
}
This is my document in MongoDB:
{
"_id": {
"$oid": "566193b0c9b5290f234242"
},
"name": "fake-name-1",
"profiles": [
{
"real-name": "fake-name-1",
"color": "fake-color-1"
},
{
"real-name": "fake-name-2",
"color": "fake-color-2",
"active": true
},
{
"real-name": "fake-name-3",
"color": "fake-color-3"
}
]
}
I'm real newbie to MondoDb, and are trying to find the document where profiles contains a real-name with "MArtin43221" and active = true.
How do I create a search query for this?
I've tried:
{"profiles": ["real-name":"MArtin43221", "active":true]}
Try elemMatch:
db.collection.find({"profiles": {$elemMatch:{"real-name":"MArtin43221", "active":true}}})
I'm trying to get mongodb query working. Collection comes in the format:
{
"_id": {
"$oid": "54651022bffebc03098b4567"
},
"browser": "ie",
"browser_version": "10.0 Desktop",
"os_version": "8",
"device": null,
"os": "Windows"
}
The following works:
{
"_id": {
"$in": [
{
"$oid": "54651022bffebc03098b4567"
},
{
"$oid": "54651022bffebc03098b4568"
}
]
}
}
However, I get a syntax error for the following:
{
"_id": {
"$in": [
ObjectId("54651022bffebc03098b4567"),
ObjectId("54651022bffebc03098b4568")
]
}
}
There are a similar questions that suggested that ObjectId should work:
How to create query with ObjectIds using java?
$all parameter in mongodb does not work with ObjectId list
The MongoLab UI uses Strict MongoDB Extended JSON so Object IDs are represented thusly, as in the second code block of the OP:
{ "$oid": "<id>" }
This should be really easy but I cant seem to get it working;
I just need to remove a sub-document that I had accidentally run and introduced undesirable info in the sub-document.
I tried - db.test.remove({}, {dcoll10:{"$exists": true}, {multi: true}); but this didnt work.
Example of document and sub-doc (dcoll10) is given below;
{
"_id": "SSS",
"ts": { "$date": 1395927614611 },
"dcoll10": [
{
"_id": "SSS",
"type": "1813",
"gro": "0.1",
},
{
"_id": "SSS",
"type": "1813",
"gro": "0.1",
}
],
"assima" : [
{......}
]
}
It sounds like you want the $unset operator which is documented here: http://docs.mongodb.org/manual/reference/operator/update/unset/