Description Usage Arguments Details Value See Also Examples
Add an index to a collection.
1 | mongo.index.create(mongo, ns, key, options = 0L)
|
mongo |
(mongo) A mongo connection object. |
ns |
(string) The namespace of the collection to which to add an index. |
key |
An object enumerating the fields in order which are to participate in the index. This object may be a vector of strings listing the key fields or a mongo.bson object containing the key fields in the desired order. Alternately, Alternately, |
options |
(integer vector) Optional flags governing the operation:
|
See http://www.mongodb.org/display/DOCS/Indexes.
NULL if successful; otherwise, a mongo.bson object describing
the error.
mongo.get.server.err()
or
mongo.get.server.err.string()
may alternately be called in
this case instead of examining the returned object.
mongo.find
,
mongo.find.one
,
mongo.insert
,
mongo.update
,
mongo.remove
,
mongo,
mongo.bson.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
# Add a city index to collection people in database test
b <- mongo.index.create(mongo, "test.people", '{"city":1}')
if (!is.null(b)) {
print(b)
stop("Server error")
}
# Add an index to collection people in database test
# which will speed up queries of age followed by name
b <- mongo.index.create(mongo, "test.people", c("age", "name"))
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append(buf, "age", 1L)
mongo.bson.buffer.append(buf, "name", 1L)
key <- mongo.bson.from.buffer(buf)
# add an index using an alternate method of specifying the key fields
b <- mongo.index.create(mongo, "test.people", key)
# create an index using list of that enumerates the key fields
b <- mongo.index.create(mongo, "test.cars", list(make=1L, model=1L))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.