common_functions.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.prepareDocs = exports.indexInformation = void 0;
  4. async function indexInformation(db, name, options) {
  5. if (options == null) {
  6. options = {};
  7. }
  8. // If we specified full information
  9. const full = options.full == null ? false : options.full;
  10. // Get the list of indexes of the specified collection
  11. const indexes = await db.collection(name).listIndexes(options).toArray();
  12. if (full)
  13. return indexes;
  14. const info = {};
  15. for (const index of indexes) {
  16. info[index.name] = Object.entries(index.key);
  17. }
  18. return info;
  19. }
  20. exports.indexInformation = indexInformation;
  21. function prepareDocs(coll, docs, options) {
  22. const forceServerObjectId = typeof options.forceServerObjectId === 'boolean'
  23. ? options.forceServerObjectId
  24. : coll.s.db.options?.forceServerObjectId;
  25. // no need to modify the docs if server sets the ObjectId
  26. if (forceServerObjectId === true) {
  27. return docs;
  28. }
  29. return docs.map(doc => {
  30. if (doc._id == null) {
  31. doc._id = coll.s.pkFactory.createPk();
  32. }
  33. return doc;
  34. });
  35. }
  36. exports.prepareDocs = prepareDocs;
  37. //# sourceMappingURL=common_functions.js.map