Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying Mongo for a NumberLong

Tags:

mongodb

I'm using mongo 2.4.

I have a collection which has these two entries:

> db.collection.find({domain: "pow.com"})
{ "_id" : ObjectId("577ee9ec6f66304109769855"), "domain" : "pow.com", "mImp" : NumberLong(38), "oImp" : NumberLong(38), "vImp" : NumberLong(120), "date" : "Thu Jul 07 2016 16:46:52 GMT-0700 (PDT)", "id" : NumberLong(3847146) }
{ "_id" : ObjectId("577ef4c44df54be7247eb497"), "domain" : "pow.com", "mImp" : NumberLong(38), "oImp" : NumberLong(38), "vImp" : NumberLong(120), "date" : ISODate("2016-10-01T00:00:00Z"), "id" : NumberLong(3847146) }

I've tried to run these queries and everytime I get no data back:

> db.collection.find({"vImp": NumberLong(38)});
> db.collection.find({vImp: NumberLong(38)});
> db.collection.find({vImp: 38});
> db.collection.find(vImp: 38)

I've tried to google around, but it seems like this should be working....

like image 324
Shail Patel Avatar asked Jul 08 '16 00:07

Shail Patel


People also ask

What is NumberLong in MongoDB?

NumberLong. The mongo shell treats all numbers as floating-point values by default. The mongo shell provides the NumberLong() wrapper to handle 64-bit integers. The NumberLong() wrapper accepts the long as a string: NumberLong("2090845886852")

How do I query data in MongoDB?

To query data from MongoDB collection, you need to use MongoDB's find() method.

Can we query MongoDB?

MongoDB Query is a way to get the data from the MongoDB database. MongoDB queries provide the simplicity in process of fetching data from the database, it's similar to SQL queries in SQL Database language.


1 Answers

I believe you are missing the "" around 38.

On MongoDB shell version: 3.0.14

db.users.find({"id":NumberLong("853969028494368768")})

in your case

db.collection.find({"vImp": NumberLong("38")})
like image 53
layser Avatar answered Sep 22 '22 14:09

layser