Full-text-search on mongoDB using Compass - mongodb

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!

Related

Basic Mongo DB Find example

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'}}})

Haskell mongodb text search

What is the status of text search with haskell mongodb driver?
There is now 'LIKE' operator in mongo similar to SQL variants, so what is the best way to search a collection or the whole db for a particular text string?
I've read some people referencing external tools but I can also see that some text search was implemented in 2.4 mongo version which is done through command interface.
There should not be any problems doing it from console but how would I do it from haskell driver? I found 'runCommand' function in the driver APIs and it looks like it should be possible to send 'text' command to the server but the signature shows that it returns only one document - not a list of documents. So how is it done correctly?
How would I efficiently search for a word or a sentence in a collection or db so that it returns a list of documents containing the word? Is it possible to do without external tools using mongo 'text search' feature? SHould it be done in the application level?
Thanks.
The result type already contains the list of documents (that contain the searched text). Unfortunately, I could not test the query on my running database, but I have used runCommand to run an aggregation (before it was implemented for the haskell driver). The result document you get for such an query looks something like this:
{ results: [
{ score : ...,
obj : { ... }
},
...
],
... ,
ok : 1
}
The result document has a field results and its value is a document with fields score and obj. So in the end, you can find each of the matched document behind the obj-field in the list of results.
For more details, you should take a look here.

db.getCollectionNames() equivalent in pymongo

mongodb db.getCollectionNames()command will give you all collection names what are all there in the current db, in a list.
I want the same output using pymongo. I googled some time and couldn't find anything like that.
Is anything like that exists ?
collection_names()
Will show you the collections of the current database.
From documentation:
collection_names()
Get a list of all the collection names in this database.
[read more]
Since pymongo 3.7, collection_names() is deprecated and the correct way to get collection names is list_collection_names()

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.