FAQ
How to set MongoDB index without using the interactive shell?

I am trying to write some auto scripts to set up collections, like

./mongoimport -d myDB -c myCollection xxx xxxx

next is to specify and create the index, but how to do this in command line?

Thanks,

Shi

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongodb-user@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

Search Discussions

  • Dan Crosta at Feb 4, 2012 at 11:31 pm
    You can use the --eval command line option to pass a command (or set of commands, separated by semicolons) to the mongo shell. The shell executes them and then exits. For example:

    mongo hostname:port/dbname --eval "db.myCollection.ensureIndex({field: 1, otherfield: -1})"

    - Dan

    On Feb 4, 2012, at 6:27 PM, Shi Yu wrote:

    How to set MongoDB index without using the interactive shell?

    I am trying to write some auto scripts to set up collections, like

    ./mongoimport -d myDB -c myCollection xxx xxxx

    next is to specify and create the index, but how to do this in command line?

    Thanks,

    Shi


    --
    You received this message because you are subscribed to the Google Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com.
    To unsubscribe from this group, send email to mongodb-user+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
    --
    You received this message because you are subscribed to the Google Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com.
    To unsubscribe from this group, send email to mongodb-user+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
  • Shi Yu at Feb 4, 2012 at 11:52 pm
    Thanks Dan! Very nice.

    Shi
    On Sat, Feb 4, 2012 at 5:31 PM, Dan Crosta wrote:

    You can use the --eval command line option to pass a command (or set of
    commands, separated by semicolons) to the mongo shell. The shell executes
    them and then exits. For example:

    mongo hostname:port/dbname --eval "db.myCollection.ensureIndex({field:
    1, otherfield: -1})"

    - Dan

    On Feb 4, 2012, at 6:27 PM, Shi Yu wrote:

    How to set MongoDB index without using the interactive shell?

    I am trying to write some auto scripts to set up collections, like

    ./mongoimport -d myDB -c myCollection xxx xxxx

    next is to specify and create the index, but how to do this in command line?
    Thanks,

    Shi


    --
    You received this message because you are subscribed to the Google
    Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com.
    To unsubscribe from this group, send email to
    mongodb-user+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/mongodb-user?hl=en.

    --
    You received this message because you are subscribed to the Google Groups
    "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com.
    To unsubscribe from this group, send email to
    mongodb-user+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/mongodb-user?hl=en.
    --
    You received this message because you are subscribed to the Google Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com.
    To unsubscribe from this group, send email to mongodb-user+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupmongodb-user @
categoriesmongodb
postedFeb 4, '12 at 11:27p
activeFeb 4, '12 at 11:52p
posts3
users2
websitemongodb.org
irc#mongodb

2 users in discussion

Shi Yu: 2 posts Dan Crosta: 1 post

People

Translate

site design / logo © 2022 Grokbase