mongo.index.TTLcreate: Add a time to live (TTL) index to a collection

Description Usage Arguments Details Value See Also Examples

View source: R/mongo_index.R

Description

Add a time to live (TTL) index to a collection

Usage

1
mongo.index.TTLcreate(mongo, ns, key, expireAfterSeconds, index_name = NULL)

Arguments

mongo

(mongo) A mongo connection object.

ns

(string) The namespace of the collection to add a TTL index to.

key

(mongo.bson) The desired field(s) to use as the basis for expiration time. The field should be of type 'Date'.

Alternately, key may be a list which will be converted to a mongo.bson object by mongo.bson.from.list().

Alternately, key may be a valid JSON character string which will be converted to a mongo.bson object by mongo.bson.from.JSON().

expireAfterSeconds

(Numeric or Integer) The time in seconds after which records should be removed.

index_name

(string) The name of the index to be created.

Details

See http://docs.mongodb.org/manual/tutorial/expire-data.

Value

NULL if the command failed. mongo.get.err() may be MONGO_COMMAND_FAILED.

(mongo.bson) The server's response if successful.

See Also

mongo.index.create

Examples

1
2
3
4
5
6
7
8
9
mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
 for (i in 1:10) mongo.insert(mongo, ns = 'test.testTTL', b = list(a = i,  last_updated = i))
 res_bson <- mongo.index.TTLcreate (mongo, ns = 'test.testTTL', key = list(last_updated = 1),
                                     expireAfterSeconds = 3600, index_name = 'last_updated_1')
 print(res_bson);
 mongo.drop(mongo, ns = 'test.testTTL')
}
mongo.destroy(mongo);

jonkatz2/rmongodb documentation built on May 19, 2019, 7:30 p.m.