Files
SEONexus/doc/mongodb.md
2026-02-22 19:42:47 +08:00

2.2 KiB


use novel 
db.dropDatabase("novel") 
use novel 
db.novel.createIndex({ "n_id": 1 }) 
db.novel.createIndex({ "og_title": 1 }) 
db.novel.createIndex({ "og_novel_status": 1 }) 
db.novel.createIndex({ "n_site_uuid": 1 }, { unique: true }) 
db.novel.createIndex({"n_related_novel.n_id": 1}) 
db.novel.createIndex({"n_forge_novel.n_forge_id": 1}) 
// db.novel.createIndex({ "og_novel_update_time": 1 })

//  {
//    "n_related_novel": [
//      {"n_id": "33", "n_source_id":"11", "og_title":"小说名字"},
//      {"n_id": "44", "n_source_id":"11", "og_title":"小说名字"},
//    ]
//  }

//  {
//    "n_forge_novel": [
//      {"n_forge_id": "33","n_forge_code": "33", "n_forge_title":"伪造小说名字"},
//      {"n_forge_id": "44","n_forge_code": "33", "n_forge_title":"伪造小说名字"},
//    ]
//  }


//  小说章节索引
db.chapter.createIndex({ "c_site_uuid": 1 }, { unique: true })
db.chapter.createIndex({ "n_id": 1 })
db.chapter.createIndex({ "c_sort_num": 1 })
db.chapter.createIndex({ "c_page": 1 })

// 分类
db.category.createIndex({"ca_name":1},{unique:true})

// 统计
db.novel_clicks.createIndex({ "n_id": 1, "nc_date": 1, "nc_type": 1 },{ unique: true });



// 查询某个资源线路的数据
db.video.find(
    { "v_play_url.douban": { $exists: true } }
).limit(10)

db.video.find(
    { "v_play_url.maotai": { $exists: true } }
).limit(10)

db.video.find(
    {
        "v_play_url.douban": { $exists: true },
        "v_play_url.maotai": { $exists: true }
    }
).limit(10)

db.video.find({
    "v_play_url.maotai": { $exists: true },
    $expr: {
        $gt: [
            { $size: { $objectToArray: "$v_play_url" } },
            1
        ]
    }
})

db.video.find({
  "v_play_url.douban": { $exists: true }
}).count()
// 删除某个资源线路的数据
db.video.updateMany(
    {},
    { $unset: { "v_play_url.douban": "" } }
)

// 删除某个资源线路的数据 30天内
db.video.find({
  created_at: {
    $gte: new Date(Date.now() - 30*24*60*60*1000)
  },
  "v_play_url.youzhi": { $exists: true }
}).count()

db.video.updateMany(
  {
    created_at: {
      $gte: new Date(Date.now() - 30*24*60*60*1000)
    },
    "v_play_url.youzhi": { $exists: true }
  },
  {
    $unset: { "v_play_url.youzhi": "" }
  }
)