Basic Mongo DB Find example - mongodb

Below is a screenshot of my mongo db collection.
i want to be able to find all record where the artist is VĂ³nia Fernandes
after reading online i was able to get all entrys from 2008 with
db.eurovision.find({},{2008:1})
The screen show below returns nothing. Ive also tried putting Artist in quotes

Try this:
db.eurovision.find({2008: {$elemMatch: {Artist:'Vonia Fernandes'}}})

Related

Full-text-search on mongoDB using Compass

I am using MongoDB Compass. I'm creating my queries in Compass query language (programming-language-agnostic, so I can port it over to other languages later via Compasss). My problem? I can't figure out what I'm doing wrong in this query. There are no docs explaining MongoDB Compass syntax for $search.
My indexed text field is called markdown_1, my query is "my" (or whatever the user enters), and the object that is being searched looks like this:
How do I get this query to return anything? As of now, it finds nothing.
Thanks!

Why the result of db.user.count() is 0 in mongo?

as you can see in the image below I just create an user even though it still gave 0 , and the same thing with collections when I run show collection it shows me one , but when when I do db.collection.count() gave me 0.
the image for db.collection.count()
I do have one document on this collection here is image from Mongo compass
As you can see there is no "user" collection in this database , there is only one collection and its name is "Databases_for_tp" so counting documents in not existing collection will show always 0.
You misenterpreted the meaniing of count() command , it counts how many documents there is in single collection , not how many collections there is in chosen database.
You can find the users when you create them in the admin database even they are created to authenticate in different database.
check:
use admin
show collections
db.system.users.count()
Note also it is a good practice to add code as text and not as pictures so it is easier to interpret.

Meteor React - Why is findOne on a single document not found in miniMongo when it does exist?

This is such a weird problem. I think it has to do with how I am querying the document. It seems like the Meteor API has changed to query documents but the docs on the website are the same.
Here is a document in the database:
meteor:PRIMARY> db.studies.findOne()
{ "_id" : ObjectId("56c12e6537014a66b16771e7"), "name" : "Study 1" }
I have subscribed to get all documents and here is what I am trying in the console to get the documents.
var study = Studies.findOne() // This works.
It returns:
_id: MongoID.ObjectID
_str: "56c12e6537014a66b16771e7"
name: 'Study 1'
I just started a new Meteor project with React. I see that my collection is returning _id: MongoId.ObjectId
This is different, I have been using Meteor for awhile with Blaze and I can't remember it returning MongoID.ObjectID instead of just the string
But now if I try and find just that one document, it does not work.
var study = Studies.findOne("56c12e6537014a66b16771e7");
or
var study = Studies.findOne({_id: "56c12e6537014a66b16771e7"});
I am positive I am queuing for the right _id field. I have double checked the ID. Why does trying to find this one document not work?
Please let me know how I can query for a document. Has something changed with Meteor? The documentation still says you can search by id string.
You need to explicitly cast object id string to an ObjectID
var study = Studies.findOne({_id: new Meteor.Collection.ObjectID("56c12e6537014a66b16771e7")});
#Jaco has the correct answer, but I wanted to answer here to clarify what the higher level issue was.
The reason why my find query was not following syntax in Meteor docs is because I inserted the document into MongoDB directly, instead of through the Meteor API.
If you insert the document directly into MongoDB, you have to query the document using the syntax #Jaco mentioned in his answer.
Similar question: Meteor - Find a document from collection via Mongo ObjectId
So instead of changing my query code, I just deleted the document I inserted directly into MongoDB, and inserted a documented using the console in the browser.
Now I can query the document like normal.
So the root of the issue is that if you insert the document directly into MongoDB, you don't get the same type of document as you would if you insert the document using the Meteor API.

How do I query for a specific MongoDB collection field inside Rails Console?

I have a Rails 3 app using MongoDB, with Mongoid as the ORM. I'd like to query for a specific field within a collection.
To query for all records of a particular collection I use User.all.to_a, as an equivalent to User.all in ActiveRecord.
Now I'd like to query for all records within a collection, but only output a particular field. In this case I'd like to see all User names. How do I do this?
I'm sure I've stared right at this in the Mongoid documentation and am just missing something...
I couldn't locate it in the new documentation for mongoid, but here is a quick link to only pointing to old 2.x.x documentation.
Basically you need to do:
User.all.only(:name).to_a

MongoDB - mongohub gui - queries by _id objectid type

I am using MongoHub GUI for MongoDB: http://mongohub.todayclose.com/
I would like to be able to query by ObjectId as this is what MongoHub is returing for _id. How to do this, something like {"_id":"4d1b4687a6d5437619000000"} is not working??
cheers,
/Marcin
try following code:
{"_id": ObjectId("4d1b4687a6d5437619000000")}
check this for more details
It looks as if MongoHub is broken in the case of supplying a function in a query (ObjectId, as galimy rightly suggested). If you enter the query as galimy suggested, then copy and paste the full query that MongoHub says it's going to execute (grayed out above the Query text input) into a connected mongo CLI console, it works fine.
I would recommend learning to use the mongo console -- I've found two bugs in 5 minutes of playing with MongoHub, and when you're typing in JSON for your queries anyway the GUI is doing very little for you.
OK, it has been fixed in recent MongoHub release. Cheers
{"_id": { $oid: "4d1b4687a6d5437619000000"}} definitely should work. Java MongoDB driver implicitly creates ObjectId object in the object has '$oid' property.
Also all the same is for date using '$date' property.