|
@@ -160,24 +160,12 @@ getStars(rating: number): string[] {
|
|
|
];
|
|
|
const BirdType=new CloudObject("BirdType");
|
|
|
const query=new CloudQuery("Birdtype");
|
|
|
- // 1. 获取所有现有鸟类名称
|
|
|
- const existingBirds = await query.find();
|
|
|
- const existingNames = existingBirds.map(bird => bird.get('name'));
|
|
|
-
|
|
|
- // 2. 找出需要删除的重复记录
|
|
|
- const birdsToDelete = existingBirds.filter(bird =>
|
|
|
- birdDataset.some(newBird => newBird.name === bird.get('name'))
|
|
|
- );
|
|
|
-
|
|
|
- // 3. 删除重复记录
|
|
|
- if (birdsToDelete.length > 0) {
|
|
|
- console.log(`找到${birdsToDelete.length}条需要删除的重复记录`);
|
|
|
- await Promise.all(birdsToDelete.map(bird => bird.destroy()));
|
|
|
- console.log('已删除所有重复鸟类记录');
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
for(const bird of birdDataset){
|
|
|
try{
|
|
|
+ // 每次循环都创建新的查询对象
|
|
|
+ const query = new CloudQuery("BirdType");
|
|
|
//检查是否已存在同名鸟类
|
|
|
query.equalTo("name",bird.name);
|
|
|
const existing=await query.first();
|