How to retrieve all values from a column in mongoDB - mongodb

I am wondering how to retrieve all values stored in a column in mongoDB, and put them in a list. find() only get all the fields, and specify <field>: <value> isn't an option as well.

If you are expecting to retrieve unique values in a column then distinct should work for you. Following is the syntax :
db.yourcollection.distinct("yourfield");
Learn more about distinct here

Related

Do I need to separate a 'whereIn' and a field value that can contain two values in firestore?

I'm querying two fields in a document. I'm using the whereIn(that's what it's called in flutter, for web it's called in) operator for one field. The other field I need to query is a string. And I want to query this value against two values. Do I need to separate the queries or is there a way to do the full query in a single query..
According to the Firestore documentation on query limitations:
You can use only one in or array-contains-any clause per query. You can't use both in and array-contains-any in the same query.
Since you need two whereIn/in clauses, you need to execute a separate query for each value in the second whereIn and then merge the results in your application code.

CouchDB filtering on key array

Given a CouchDb view that emits like this:
emit([doc.name, doc.date], doc)
How to filter on multiple doc.name values? Below doesn't seem to work.
keys=[["name1",{}],["name2",{}],["name3",{}]]
When you specify the keys parameter, you are specifying an exact match. Assuming you want a range query (every document with name="name1" no matter the date) then you need to query with a startkey and an endkey:
?startkey=["name1", ""]&endkey=["name1", {}]
And will have to repeat the query for each name.

mongoid distinct with matching

In mongodb you could use command like
db.sessions.distinct("Ip",{ 'Application': '123'})
which will return all unique ip for the selected application. How to do that via Mongoid?
I trying to pass 2 argument in distinct function but it fails with exception 'ArgumentError: wrong number of arguments (2 for 1)'
Distinct in Mongoid takes one argument -- the field you wish to filter distinct on. So in your case, you could chain a where clause w/a distinct like so:
YourModel.where(Application: '123').distinct(:Ip)
This would produce a collection of distinct YourModel's by field Ip where the field Application is equal to '123'.
Show you full distinct query, please.
I try follow syntax with users collection(3 documents with name Bob):
db.users.distinct("_id", {name: "Bob"})
And It's works:
[
ObjectId("5121792d499af102889f2576"),
ObjectId("5121792e499af102889f2577"),
ObjectId("5121792f499af102889f2578")
]
My MongoDB version is 2.2.0

command for distinct gives only one selected key value, it does not provide whole document?

In mongodb, while I run command to get distinct record from collection, It returns only key value for each record, it does not provide whole record data.
From the documentation of MongoDb :
The distinct command returns returns a list of distinct values for the given key across a collection.
It does not return the whole object, it returns the list of distinct values. See the documentation here.
For more information please provide an example and explain in detail.

Is there a way to fetch max and min values in Sphinx?

Im using sphinx for document search. Each document has list of integer parameters, like "length", "publication date (unix)", popularity, ... .
The search process itself works fine. But is there a way to get a maximum and minimum fields values for a specified search query?
The main purpose is to generate a search form which will contain filter fields so user can select document`s length.
Or maybe there is another way to solve this problem?
It is possible if length, date etc are defined as attributes.
http://www.sphinxsearch.com/docs/current.html#attributes
Attributes are additional values
associated with each document that can
be used to perform additional
filtering and sorting during search.
Try GroupBy function by 'length' and select mix(length), max(lenght).
In SphinxQl it is like:
select mix(length), max(lenght) from index_123 group by length
The same for other attributes.