handling of _id in filter
This commit is contained in:
parent
c66225c93d
commit
7f87cff4de
16
lib/ws.js
16
lib/ws.js
@ -1,8 +1,22 @@
|
||||
import { WebSocketServer } from 'ws';
|
||||
import { ObjectId } from 'mongodb';
|
||||
|
||||
let wss;
|
||||
let connections = [];
|
||||
|
||||
function replaceIdInFilter (filter) {
|
||||
if (filter) {
|
||||
for (const key in filter) {
|
||||
if (key == '_id' && typeof filter[key] == 'string') {
|
||||
filter[key] = new ObjectId(filter[key]);
|
||||
} else if (typeof filter[key] == 'object') {
|
||||
filter[key] = replaceIdInFilter(filter[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return filter;
|
||||
}
|
||||
|
||||
export function init(cfg, db) {
|
||||
wss = new WebSocketServer(cfg);
|
||||
|
||||
@ -21,7 +35,7 @@ export function init(cfg, db) {
|
||||
case "set":
|
||||
db.persist(
|
||||
message.subject,
|
||||
message.filter,
|
||||
replaceIdInFilter(message.filter),
|
||||
message.field,
|
||||
message.value
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user