delete(collection, id) { return this.connect() .then(db => db.collection(collection).deleteOne({ _id: ObjectId(id) })) .then(() => id); }
async update(collection, id, data) { const db = await this.connect(); const result = await db .collection(collection) .updateOne({ _id: ObjectId(id) }, { $set: data }, { upsert: true }); return result.insertedId; }
this.clients.find({ _id: ObjectId(location) }) .limit(1).next(function(err, result) { if (err) { callback(err); } else if (result === null) { callback(new errors.DeviceNotFound()); } else { callback(null, Object.assign({ location: result._id }, result)); } });
/** * * @param whereClause * @param projection * @returns {Promise<Promise<*>|Query|void|Promise<*|undefined>|Promise<*>>} */ async findOne(whereClause = {}, projection = {}) { whereClause = (whereClause && whereClause._id) ? { ...whereClause, _id: ObjectId(whereClause._id) } : whereClause; return this.model.findOne(whereClause, projection); }
// Delete the roleAction with the given actionId; let deleteRoleAction = function(actionId, cb) { let query = {_id: ObjectId(actionId)}; actions.findOneAndDelete(query, cb); }
get(collection, id) { debug(`${this.dbName} -> ${collection} -> get -> ${id}`); return this.connection().then(db => { return db.collection(collection).findOne({ _id: ObjectId(id) }); }); }
router.route('/ajax/comment').get((req, res) => { const db = dbUtil.getDB(); const id = req.query.id; db.collection('comments').findOne({ _id: ObjectId(id) }, function(err, comment){ db.collection('users').findOne({ _id: comment.author }, function(err, user){ comment.author = user; res.json({comment: comment}); }); }); });
async getAll(queryParams, order) { console.log(queryParams); const query = queryParams || {}; if (query && query.userId) { console.log(`query.userID`, query); query.userId = ObjectId(query.userId); } const tasks = await this.mongoDB.getAll(this.collection, query, order); return tasks || []; }
this.clients.findOneAndDelete({ _id: ObjectId(location), }, function(err, result) { if (err) { callback(err); } else if (result.value === null) { callback(new errors.DeviceNotFound()); } else { callback(null, result.value); } });
async delete({ _id }) { if (!this.admin || !this.admin.publicity) { throw 403 } let activityCollection = await mongodb('herald_activity') let activityClickCollection = await mongodb('herald_activity_click') //await db.activity.remove({ aid }) await activityCollection.deleteOne({ _id: ObjectId(_id) }) await activityClickCollection.deleteMany({ aid: _id }) return 'OK' }
get(collection, id) { return this.connect().then(db => { return db.collection(collection).findOne({ _id: ObjectId(id) }); }); }
function getProduct( productId, neededParams={} ){ return new Promise((resolve, reject)=>{ db.db.collection(collection).findOne({_id: ObjectId(productId)}, neededParams) .then(product=>{ resolve(product) }) .catch(reject) }) }
// Update the auth action with the given actionId, to have the roleId as the default role assignment. let updateAuthenticationAction = function(actionId, roleId, cb) { let query = {_id: ObjectId(actionId)}; let update = {$set: {'settings.role': ObjectId(roleId)}}; actions.findOneAndUpdate(query, update, cb); }
delete(collection, id) { debug(`${this.dbName} -> ${collection} -> delete -> ${id}`); return this.connection() .then(db => { return db.collection(collection).deleteOne({ _id: ObjectId(id) }); }) .then(result => result.result); }
async put({ activity }) { if (!this.admin || !this.admin.publicity) { throw 403 } let activityCollection = await mongodb('herald_activity') //let activityClickCollection = await mongodb('herald_activity_click') //await db.activity.update({ aid: activity.aid }, activity) await activityCollection.updateOne({ _id: ObjectId(activity._id) }, { $set: activity }) return 'OK' }