
mongotemplate
Javaの神
这个作者很懒,什么都没留下…
展开
-
记录一次Mongotemplate的And和Or的各种套
需求是查询用户的行程安排信息 查询用户过去七天到未来的行程安排, 也就是说数据必须满足如下条件 1.见面时间 >= 当前时间-7天 2.用户id=发送者id,且发送人确认情况=0或者=null 或者用户id=接收者,且发送人确认情况=0或者=null 以上两个表示用户没有确认或者否认这个记录,所以进行展示 3.行程必须是被同意过的 4.行程必须是未见面的 5.指定用户mysql大概的写法 用mongoTemplate的写法 以及 都相当于开启了一个 当里面的或者满足时这个为,则命中,嵌套的情况下亦是如此,整原创 2022-06-22 15:49:12 · 924 阅读 · 0 评论 -
MongoDB使用查询语句查询信息时查出来为空
有如下数据 但是: 都查不出来,,唯独 好家伙。。。 询问了一下朋友,mongo是严格按照数据类型查询的。。 比如按照_id字段就一定要使用ObjectId(“xxxxxxxxx”) 这里改一下 顺便记录一下使用_id查询 ...原创 2022-04-23 20:22:54 · 1743 阅读 · 0 评论 -
MongoDB的一些常规查询以及操作
索引 创建索引 #说明:1表示升序创建索引,-1表示降序创建索引 >db.user.createIndex({'age':1}) { "createdCollectionAutomatically" : false, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } 删除索引 #删除索引 db.user.dropIndex("age_1") #或者,删除除了_id之外的索引 db.user.dropIndexes()原创 2022-01-19 18:32:30 · 927 阅读 · 0 评论 -
【笔记】记录一下今天mongo的几个用法【批量添加】【定点更新】【批量删除】
目录批量添加批量删除指定字段更新 批量添加 mongotemplate.insert /** * 批量保存消息对象 * @param notification * @return */ @Override public List<Notification> sendNotificationList(List<Notification> notification) { return (List<Notification>) mongoTemplate.ins原创 2021-11-22 19:09:15 · 453 阅读 · 0 评论 -
一个关于继承和mongodb读写的笔记
本来不想记的,,,想想还是信不过自己的记性,还是记一下吧 场景: 一个基础超类:Person 两个对象继承这个超类:Diaomao,Fuerdie 两个对象有三条相同属性和一条不同属性 共用crud接口在mongo进行操作 Pojo: @Data public class Person { } @EqualsAndHashCode(callSuper = true) @Data @Document("person") public class Fuerdie extends Person {原创 2021-11-18 17:52:24 · 615 阅读 · 0 评论 -
记录一次mongodb错误
*************************** APPLICATION FAILED TO START *************************** Description: An attempt was made to call a method that does not exist. The attempt was made from the following location: org.springframework.boot.autoconfigure.mong.原创 2021-11-17 20:38:09 · 1717 阅读 · 2 评论 -
MongoTemplate笔记---记录一次MongoDb的关联查询
/** * 分页查询所有idea信息,按点赞数排序 * @param page * @param size * @param appVersion 查询的模式,当前版本,投票中 * @return */ @Override public List<UserIdea> userIdeaFindPage(Integer page, Integer size, Integer appVersion) { ...原创 2021-11-12 18:20:20 · 1565 阅读 · 0 评论 -
记录一次Mongodb-mongotemplate的聚合查询
首先表结构如下 需求: 这是一个点赞记录表,要求按照点赞次数排行,分页查询 这里就是需要我们按照topicOid分组并统计次数按照次数倒序排 这里需要使用管道聚合查询,顾名思义就像一个管道一样,上一个处理完的数据传递给下一个; 这里有两种写法,一种是使用原生的语句字符串调用,一种是使用封装好的Mongotemplate进行查询; 首先是原生 db.ad_topic_like.aggregate( [ {$match:{type:{$eq:1},appVersion:{$eq:4}}}, {$group:{原创 2021-11-12 11:56:22 · 3280 阅读 · 0 评论 -
MongoBD 找不到主键字段 mongotemplate No property ‘id‘ found on Did you mean: Id,id? 报错
今天在使用mongo的时候发现报找不到字段错误 _id失败了org.springframework.data.mapping.context.InvalidPersistentPropertyPath: No property 'id' found on class com.sabedoria.idea24payadminbackground.pojo.po.sys.SysAuth! Did you mean: Id,id? 发现是因为字段的id我使用了大写Id开头,导致字段对应不上,哪怕指定也不行,而且就原创 2021-09-04 12:46:17 · 1648 阅读 · 0 评论 -
MongoDB;Java-MongoTemplate分页查询+Or查询
分页查询: 创建分页请求: 记得一定要手动给他page-1 Pageable pageable = PageRequest.of(page-1,limit,Sort.by(Sort.Order.desc("created"))); 然后 将分页请求with加进去query就可以了 Query query = Query.query().with(pageable); Or查询的使用: 首先创建一个:条件对象 Criteria criteria = new Criteria(); 在条件对象中添加Or条原创 2021-08-03 17:05:11 · 1133 阅读 · 1 评论