Find(ID) of Mongo returns nothing

Asked

Viewed 275 times

1

I have a collection called users on Mongo with approximately 1000 values. Access Mongo through Mongodb . NET Driver, at the moment everything works normally. But these past few days I’ve been wanting to retrieve some documents from this collection manually, and I didn’t want to have to tamper with my code for this.

I executed: db.usuarios.find({}) Who returned me a large amount of documents(Proving that it is working..)

But when executing:

db.usuarios.find({"_id":"295092462215757825"}) nothing returns me. until I tried:

db.usuarios.find({"_id":295092462215757825}) and nothing. as shown in the image below..

Imagem do que mostra Source code for my Github project https://github.com/ZaynBot/ZaynBot

The ID is auto-generated by my code, so it is not an Objectid but a ulong.

What could possibly result in no value? I’m sure there is even why I got the value through Mongodb . NET Driver.

  • Was this find by id working before or hadn’t you tried it yet? Another thing: you can post in (code format) a sample of the return of your findAll, which contains a document?

  • @Pedroramos find works on the ids that appear in findAll, or at least on the initials.. This one form?

  • @Pedroramos used the Robo 3T and I could see all the documents, I can look one by one, but when I use the find does not appear, even being in Robo 3T.. Until I copied the code that appears in Robo 3T and not found in Mongo...

  • 1

    @Pedroramos Thanks, I think I found the problem, in case I was not converting the number to ulong, only putting the same raw number, after sending a sample of findAll I noticed and decided to test. I went to try with db.usuarios.find({"_id":NumberLong("383711472221421589")}) he is now finding all the documents I ask for. D

  • All right, then. I’m glad you made it!

1 answer

0


Since Id is long type, I did the following way that returned me the document:

db.usuarios.find(({"_id" : NumberLong("87604980344721408")})

Trying in the following ways returned nothing:

db.usuarios.find(({"_id" : NumberLong(87604980344721408)})

db.usuarios.find(({"_id" : 87604980344721408)})

db.usuarios.find(87604980344721408)

Tip for anyone in trouble.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.