试图获得最后一个记录值一但不起作用。如何在猫鼬中做到这一点。
mongodb 中的示例数据记录:
[
{
_id: 5f0c73f69b34214310d0acee,
name: "Test",
age: 28,
voice: "Not Tested"
},
{
_id: 5f0c73f69b34214310d0akke,
name: "Test2",
age: 38,
voice: "Tested"
}
]
Run Code Online (Sandbox Code Playgroud)
猫鼬查询:
voice
最后一条记录中的属性值是“已测试”,因此我尝试获取该值。
var Order = mongoose.model(collectionName);
Order.find({}).sort({ _id: -1 }).limit(1).then((products) => {
products.findOne({voice}, function(err,obj) {
console.log(obj);//Output should be = Tested
});
});
Run Code Online (Sandbox Code Playgroud) 尝试使用 crypto-js 加密和解密 json 数据。但不工作。如何找到解决方案。如果有人知道,请帮助找到解决方案。
演示:https : //stackblitz.com/edit/angular-ivy-nwhkgz?file=src%2Fapp%2Fapp.component.ts
storageData=
[
{
"customerInfo": {
"Micheal": 1,
"Milson": 2
},
"mycart": {
"Ol1": 1,
"Ol3": 1
},
"cartItemsList": [
{
"pid": "Ol1",
"name": "Avacota",
"qty": 1
},
{
"pid": "Ol3",
"name": "Kaliflower",
"qty": 1
}
],
"cartTotal": 2
}
];
ngOnInit(){
//Encrypt Info
this.encryptInfo = encodeURIComponent(CryptoJS.AES.encrypt(this.storageData, 'secret key 123').toString());
console.log("encryptInfo");
console.log(this.encryptInfo);
//Decrypt Info
var deData= CryptoJS.AES.decrypt(this.encryptInfo, 'secret key 123');
this.decryptedInfo = decodeURIComponent(deData.toString(CryptoJS.enc.Utf8));
console.log("decryptedInfo");
console.log(this.decryptedInfo);
}
Run Code Online (Sandbox Code Playgroud) angular8 ×1
cryptojs ×1
encryption ×1
mongodb ×1
mongoose ×1
node-crypto ×1
node.js ×1
typescript ×1