@ronmu/mongodb
v1.0.11-20241014-1412.0
Published
> Mongodb 客户端
Downloads
277
Readme
@ronmu/mongodb
Mongodb 客户端
安装使用
npm install @ronmu/mongodb
pnpm install @ronmu/mongodb
例子代码
import { MONGODB } from "@ronmu/mongodb";
(async () => {
const mongoInstance = await MONGODB.getInstance('mongodb://test:111111@localhost:27017/test', {
appName: 'MyTsTestApp'
});
const collections = await mongoInstance.listCollections({
name: /^a/ig
}, { nameOnly: true });
let index = 0;
for await (const collection of collections) {
console.group(`Index: ${index}, Collection: ${collection.name}`);
console.log(`count:`, await mongoInstance.count(collection.name));
console.log(`stats:`, await mongoInstance.stats(collection.name));
console.groupEnd();
index++;
}
const objectIds = ['66a21df3753988d72494eaec', '66a21df3753988d72494eaec', '5f0fbcaf77a8832fd4f8eaad'];
const abc = await mongoInstance.searchRefByObjectIds(objectIds);
console.log(abc);
const keyWords = ['北京A组'];
const xyz = await mongoInstance.searchRefByKeywords(keyWords);
console.log(xyz);
})()