時(shí)間:2024-02-21 13:55作者:下載吧人氣:37
前言
aggregate 翻譯過(guò)來(lái)是聚合的意思, 但是在實(shí)際的使用的它的體驗(yàn)特別像linux中的管道, 每個(gè)管道處理完之后再把結(jié)果交個(gè)下一個(gè)管道, 你的數(shù)據(jù)就像水流, 最后通過(guò)各個(gè)管道你能夠得到你想要的數(shù)據(jù)
我們一般用Aggregate做什么
aggregate查詢文檔
在這里我主要想記錄一下mongodb在地理位置信息查詢中使用到的技術(shù),不僅可以查詢到 距離 還可以按照距離排序
$geoNear 地理位置信息查詢
首先我們的坐標(biāo)數(shù)據(jù)在庫(kù)里面怎么存, 類型為 Array , 記得加 2d 索引, 當(dāng)然還有3d 索引, 目前還沒(méi)有用到
const storeschema = new mongoose.Schema({ name: { type: String, required: true }, point: { type: Array, required: true }, // [lon, lat] }); storeschema.index({ point: '2d' }); return mongoose.model('store', storechema);
網(wǎng)友評(píng)論