Pietro Fragnito
Pietro Fragnito

Reputation: 347

MongoDB find returns nothing

I'm starting learning and using MongoDB. I'm following a basic sample consisting creating a collection with one document. So I first switched to a test db using use testdb. Then I executed this command in order to insert a new document into a new collection:

db.websites.insert({ name: "homepage", _id: "http://www.html.it", tags: ["Development", "Design", "System"]});

This command returned to me: WriteResult({ "nInserted" : 1 })

Finally I wanna show the last inserted document using

db.website.find()

But, (and this is the problem), it returns me nothing!! No errors, no documents...

Any suggestions?

Thanks

Upvotes: 0

Views: 2873

Answers (2)

Pietro Fragnito
Pietro Fragnito

Reputation: 347

As understood by @chf ,the collection name in db.website.find() command was wrong: the correct one is websites (with the s).

So the Begineer Guide contains an error.

Thanks to all and sorry for the trivial question.

Upvotes: 0

Florian Bury
Florian Bury

Reputation: 91

apparently your insertion is correctly done (it's indicated by the output in the shell). To do your test correctly, you have to

  1. Create a collection : db.createCollection('collectionName');
  2. Use this collectionn : use collectionName;
  3. Insert some data inside : db.websites.insert({ name: "homepage", _id: "http://www.html.it", tags: ["Development", "Design", "System"]});
  4. Use the command find : db.websites.find();

To find a result, be sure you're using the correct collection before do the command find.

Upvotes: 1

Related Questions