Skip to the content.

Bulk importing documents

This function implements the HTTP API for bulk imports.

collection.import

async collection.import(data, [opts]): Object

Bulk imports the given data into the collection.

Arguments

For more information on the opts object, see the HTTP API documentation for bulk imports.

Examples

const db = new Database();
const collection = db.collection("users");

const result = await collection.import(
  [
    { username: "jcd", password: "bionicman" },
    { username: "jreyes", password: "amigo" },
    { username: "ghermann", password: "zeitgeist" }
  ],
  { type: "documents" } // optional
);

// -- or --

const buf = fs.readFileSync("dx_users.json");
// [
//   {"username": "jcd", "password": "bionicman"},
//   {"username": "jreyes", "password": "amigo"},
//   {"username": "ghermann", "password": "zeitgeist"}
// ]
const result = await collection.import(
  buf,
  { type: "array" } // optional
);

// -- or --

const result = await collection.import(
  [
    ["username", "password"],
    ["jcd", "bionicman"],
    ["jreyes", "amigo"],
    ["ghermann", "zeitgeist"]
  ],
  { type: null } // required
);