mongo-shell

mongodb query on DBRef type

醉酒当歌 提交于 2020-01-05 08:36:22
问题 How do I turn this query in a valid mongodb Query in mongodb shell. { 'cars.owner.$ref' : 'users' } cars.owner is a DBRef here, but $ref is invalid I get this error: "$err" : "Positional operator does not match the query specifier." My objective here is to figure out if there are any cars "owned" by different collections then users. 回答1: MongoDB documentation (database-reference) says following: MongoDB applications use one of two methods for relating documents: Manual references where you

hex instead of base64 in BinData() - MongoDB

社会主义新天地 提交于 2020-01-04 04:48:08
问题 Is there a way to send hex of binary value instead of base64 to BinData() in mongo ? 回答1: HexData(3,"00112233445566778899aabbccddeeff") or UUID("00112233445566778899aabbccddeeff") both will result: BinData(3,"ABEiM0RVZneImaq7zN3u/w==") And the other way around: BinData(3,"ABEiM0RVZneImaq7zN3u/w==").hex() will result: 00112233445566778899aabbccddeeff 回答2: Only Use HexData(subtype, hexstr) 来源: https://stackoverflow.com/questions/28945535/hex-instead-of-base64-in-bindata-mongodb

hex instead of base64 in BinData() - MongoDB

放肆的年华 提交于 2020-01-04 04:48:02
问题 Is there a way to send hex of binary value instead of base64 to BinData() in mongo ? 回答1: HexData(3,"00112233445566778899aabbccddeeff") or UUID("00112233445566778899aabbccddeeff") both will result: BinData(3,"ABEiM0RVZneImaq7zN3u/w==") And the other way around: BinData(3,"ABEiM0RVZneImaq7zN3u/w==").hex() will result: 00112233445566778899aabbccddeeff 回答2: Only Use HexData(subtype, hexstr) 来源: https://stackoverflow.com/questions/28945535/hex-instead-of-base64-in-bindata-mongodb

Mongodb exact phrase search

半腔热情 提交于 2019-12-31 04:48:24
问题 As I understood from Mongodb documentation of text search. if i want to search about Java or (coffee shop) I need to do it like {$text:{$search:"Java \"coffee shop\""}} Exact Phrase search in mongodb documentation so it should return all the documents contain Java or (coffee shop) . but it acts exactly as Java and (coffee shop) . so I think that i didn't get it right from the documentation. so please. I need clear explanation for why i got that result? and how to get the required output Java

Mongodb can't find object with too long _id

老子叫甜甜 提交于 2019-12-25 09:04:53
问题 I have a little bit strange situation. I persist objects in collection "refs" explicitly setting _id. So I have objects with very big id's. db.refs.find().sort({_id: -1}); // {_id: 9200000000165761625} // ... But when I try to find object with biggest id in mongo shell it returns nothing: db.refs.find({_id: 9200000000165761625}); // nothing But! db.refs.find({_id: 9200000000165761625}).count(); // return 1 How could this happen? 回答1: i could not reproduce your problem. i was able to

MongoDB: find execution time for count() command on millions of records in a collection?

自闭症网瘾萝莉.ら 提交于 2019-12-24 13:52:29
问题 I am trying to find time required to perform a count() on a collection which is consisting of millions of testdata records, with following scenario:- 1) From 1st Mongo shell I am inserting millions of records into collection using a code for (var i = 0; i < 10000000; ++i){ db.unicorns.insert({name: 'sampleName', gender: 'm', weight: '440' }); } 2) From 2ndMongo shell I am trying to find count() on that collection( Imp: while insertion is still getting executed on 1st Mongo Shell) db.unicorns

How to run a mongo script from Heroku scheduler?

点点圈 提交于 2019-12-23 23:36:50
问题 I have implemented a javascript script for my mongo database. This script is called getMetrics.js and I am able to execute it by running: mongo getMetrics.js from my computer. Now I want to automatically execute that script one time per day. To do so, I have created a Heroku app and I added to it the scheduler add-on (https://devcenter.heroku.com/articles/scheduler). My main problem is that in order to be run, my task will execute the command "mongo getMetrics.js" and it will failed because I

MongoDb explain failed: “unknown top level operator: $query”

耗尽温柔 提交于 2019-12-23 15:25:52
问题 I'm trying to obtain explain from quite simple query. It uses posts collection with following schema: > db.posts.findOne() { "_id" : ObjectId("55236e6182bf196454a952b6"), "Content" : "wuOfCjKborHcxkoyXzXiW", "CreatedAtUtc" : ISODate("2014-01-18T23:59:30.023Z"), "Tags" : [ "sjM", "Van", "Orm" ], "Title" : "msAQAbQwAl", "Author" : "yIIhato", "Comments" : [ ] } Query I want to explain is this: db.posts.find( { $query: {}, $orderby: { "CreatedAtUtc" : -1 } } ) It produces proper result without

Cannot use commands write mode error, Degrading to compatibility mode

爱⌒轻易说出口 提交于 2019-12-21 06:56:26
问题 I just play with mongo shell and came across with Cannot use commands write mode, degrading to compatibility mode . I connected to remote mongo server (mongolab) and tried to insert new record to collection by my simple script: // script.js db = connect(host + ":" + port +"/" + dbName); db.auth(username, password); db.test2.insert({ item: "card", qty: 15 }); I run script by mongo script.js and got: MongoDB shell version: 2.6.3 connecting to: test connecting to: my.mongolab.com:port/DBname

How to make comlex query MongoDB with Powershell

爷,独闯天下 提交于 2019-12-21 05:36:23
问题 I need to retrieve data from mongoDB using Powershell. Let's say I have db.orders collection and need to retrieve only orders created during last week and retrieve only specific columns for instance _id, status, createdAt fields. Orders collection schema { "_id": ObjectId("56cf9bab78e9fd46ec557d69"), "status" : "ordered", ... "total": 343, "createdAt": ISODate("2016-01-15T17:29:09.342Z") } I can query it in mongo shell like this db.orders.find({ "createdAt" : { $lt: new Date(), $gte: new Date