apoc.mongodb.insert

Procedure APOC Full Deprecated

apoc.mongodb.insert(host-or-key,db,collection,documents) - inserts the given documents into the mongodb collection

Signature

apoc.mongodb.insert(host :: STRING?, db :: STRING?, collection :: STRING?, documents :: LIST? OF MAP?) :: VOID

Input parameters

Name Type Default

host

STRING?

null

db

STRING?

null

collection

STRING?

null

documents

LIST? OF MAP?

null

Install Dependencies

The Mongo procedures have dependencies on a client library that is not included in the APOC Library.

This dependency is included in apoc-mongodb-dependencies-4.1.0.11.jar, which can be downloaded from the releases page. Once that file is downloaded, it should be placed in the plugins directory and the Neo4j Server restarted.

Usage Examples

The examples in this section are based on a Mongo DB instance with a pre-populate twitter dataset. You can find instructions for setting this up at github.com/neo4j-examples/mongo-example.

We’re going to inser a document with the key foo with value bar:

Cypher
CALL apoc.mongodb.insert('mongodb://mongo:neo4j@mongo:27017', 'test', 'tweets',[{foo:'bar'}]);

We can check that our document has been stored using apoc.mongodb.find, as shown below:

Cypher
CALL apoc.mongodb.find('mongodb://mongo:neo4j@mongo:27017', 'test', 'tweets', {foo: "bar"}, null, null);
Table 1. Results
value

{foo: "bar", _id: "5fbbdbecb834740006b242dc"}