I need to find out distinct values(for example : CreationDate or SourceSystem) in MongoDB using MongoVUE. FYI, I can only use the trial version of the same.
I don't think you can do that using MongoVUE. You can do it through MongoDB shell running a command like this:
db.[Collection Name].distinct({Property Name})
ex: db.students.distinct('age')
db.students.distinct('age').length; // gives you the record count
I usually find SQL to Mongo Mapping Chart page useful in these case ( http://www.mongodb.org/display/DOCS/SQL+to+Mongo+Mapping+Chart )
From having a quick look, I can't see how you can either, as the "Find" feature forces you to use:
db.[collectionName].find({...})
so doesn't allow you to do:
db.[collectionName].distinct({...})
I recommend using the normal command line executable for Mongo instead of MongoVUE, then you can use the commands from the 10Gen documentation:
http://www.mongodb.org/display/DOCS/Aggregation#Aggregation-Distinct
Related
How can I change the to_tsvector configuration to use a simple tokenization rule like:
lowercase
split by spaces only
Executing the following query:
SELECT to_tsvector('english', 'birthday=19770531 Name=John-Oliver Age=44 Code=AAA-345')
I get these lexemes:
'-345':9 '19770531':2 '44':6 'aaa':8 'age':5 'birthday':1 'code':7 'john':4 'name':3
The kind of searching I'm looking for is like:
(!birthday | birthday=19770531) & (code=AAA-345)
It means, get me all records that has a text "birthday=19770531" or doesn't have "birthday" at all, and a text equals to "code=AAA-345"). The way lexemes are being created it is not possible. I was expecting to have something like this:
'birthday=19770531':1 'age=44':2 'code=aaa-345':4 'name=john-oliver':3
You would have to code a custom parser. This can only be done in C.
But you might be able to use the existing testing parser test_parser, it seems to do what you want. If not, it would at least be a good starting point.
The problem may be that this is in src/test/modules/, and I don't think it ships with most installation packaging. So it might take some effort to get it to install. It would depend on your OS, version, and package manager.
Is there a way to tell Mongo to pretty print output? Currently, everything is output to a single line and it's difficult to read, especially with nested arrays and documents.
(note: this is answer to original version of the question, which did not have requirements for "default")
You can ask it to be pretty.
db.collection.find().pretty()
You can add
DBQuery.prototype._prettyShell = true
to your file in $HOME/.mongorc.js to enable pretty print globally by default.
(note: this is answer to the updated question)
You can just do this on the CLI:
echo DBQuery.prototype._prettyShell = true >> ~/.mongorc.js
And it's always going to output pretty results.
Since it is basically a javascript shell, you can also use toArray():
db.collection.find().toArray()
However, this will print all the documents of the collection unlike pretty() that will allow you to iterate.
Refer: http://docs.mongodb.org/manual/reference/method/cursor.toArray/
Oh so i guess .pretty() is equal to:
db.collection.find().forEach(printjson);
Give a try to Mongo-hacker(node module), it alway prints pretty.
https://github.com/TylerBrock/mongo-hacker
More it enhances mongo shell (supports only ver>2.4, current ver is 3.0), like
Colorization
Additional shell commands (count documents/count docs/etc)
API Additions (db.collection.find({ ... }).last(), db.collection.find({ ... }).reverse(), etc)
Aggregation Framework
I am using for while in production env, no problems yet.
Got to the question but could not figure out how to print it from externally-loaded mongo. So:
This works is for console: and is prefered in console, but does not work in external mongo-loaded javascript:
db.quizes.find().pretty()
This works in external mongo-loaded javscript:
db.quizes.find().forEach(printjson)
Check this out:
db.collection.find().pretty()
I have a collection named GoldenGlobes-emotion in my MongoDB 2.6.9
I found I can not access this collection from the MongoDB shell
When ever I try to access the collection, for example
db.GoldenGlobes-emotion.findOne()
I always got this:
ReferenceError: emotion is not defined
But it works well when I access the collection form Python with PyMongo.
Is this a shell bug?
Or '-' is a reserved character?
Try db["GoldenGlobes-emotion"].findOne().
The MongoDB shell is a Javascript interpreter. Javascript does not allow hyphens in variable names, because it interprets them as the minus-operator. However, you can also access object-fields with string literals by using the array-syntax. In that case, this restriction does not apply.
Can not delete the collection from the shell,
The thing that the collection is available and my php script is accessing it (selecting|updating)
But when I used:
db._registration.drop()
it gives me an error:
Date, JS Error: TypeErrorL db._registration has no properties (shell): 1
The problem is not with deleting the collection. The problem is with accessing the collection. So you would not be able to update, find or do anything with it from the shell. As it was pointed in mongodb JIRA, this is a bug when a collection has characters like _, - or .
Nevertheless this type of names for collections is acceptable, but it cause a problem in shell.
You can delete it in shell with this command:
db.getCollection("_registration").drop()
or this
db['my-collection'].drop()
but I would rather rename it (of course if it is possible and will not end up with a lot of changing).
You can also use:
db["_registration"].drop()
which syntax works in JS as well.
For some reason the double quotes "_registration" did not workfor me .. but single quote '_registration' worked
Is there a way to tell Mongo to pretty print output? Currently, everything is output to a single line and it's difficult to read, especially with nested arrays and documents.
(note: this is answer to original version of the question, which did not have requirements for "default")
You can ask it to be pretty.
db.collection.find().pretty()
You can add
DBQuery.prototype._prettyShell = true
to your file in $HOME/.mongorc.js to enable pretty print globally by default.
(note: this is answer to the updated question)
You can just do this on the CLI:
echo DBQuery.prototype._prettyShell = true >> ~/.mongorc.js
And it's always going to output pretty results.
Since it is basically a javascript shell, you can also use toArray():
db.collection.find().toArray()
However, this will print all the documents of the collection unlike pretty() that will allow you to iterate.
Refer: http://docs.mongodb.org/manual/reference/method/cursor.toArray/
Oh so i guess .pretty() is equal to:
db.collection.find().forEach(printjson);
Give a try to Mongo-hacker(node module), it alway prints pretty.
https://github.com/TylerBrock/mongo-hacker
More it enhances mongo shell (supports only ver>2.4, current ver is 3.0), like
Colorization
Additional shell commands (count documents/count docs/etc)
API Additions (db.collection.find({ ... }).last(), db.collection.find({ ... }).reverse(), etc)
Aggregation Framework
I am using for while in production env, no problems yet.
Got to the question but could not figure out how to print it from externally-loaded mongo. So:
This works is for console: and is prefered in console, but does not work in external mongo-loaded javascript:
db.quizes.find().pretty()
This works in external mongo-loaded javscript:
db.quizes.find().forEach(printjson)
Check this out:
db.collection.find().pretty()