Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
find (entitySet, query, fields, opts = {}) {
const documents = getDocuments(this.documents[entitySet], opts).map((d) => {
if (opts.transaction && d.$transaction.active[opts.transaction.id] && d.$transaction.active[opts.transaction.id].updatedDoc) {
return d.$transaction.active[opts.transaction.id].updatedDoc
}
return d
})
const cursor = mingo.find(documents, query, fields)
cursor.toArray = () => cursor.all().map((e) => omit(extend(true, {}, e), '$transaction'))
return cursor
},
update (entitySet, q, u, opts = {}) {
const documents = getDocuments(this.documents[entitySet], opts)
const toUpdate = mingo.find(documents, q).all()
if (toUpdate.length === 0 && opts.upsert) {
this.insert(entitySet, u.$set, opts)
} else {
toUpdate.forEach((d) => {
if (opts.transaction) {
d.$transaction = d.$transaction || { active: {} }
d.$transaction.active[opts.transaction.id] = d.$transaction.active[opts.transaction.id] || {}
d.$transaction.active[opts.transaction.id].updatedDoc = omit(extend(true, {}, d, u.$set), '$transaction')
d.$transaction.active[opts.transaction.id].state = 'update'
} else {
Object.assign(d, u.$set || {})
}
})
}