当前位置: 首页 > news >正文

1有免费建网站济南企业建设网站

1有免费建网站,济南企业建设网站,网站建设内容是经营项目吗,深圳网站制作首荐祥奔科技文章目录 1. $eq 比较查询操作符1.1 基本类型字段1.2 嵌入式文档字段1.3 数组字段 2. $eleMatch 数组查询操作符2.1 基本类型数组字段2.2 基本类型数组字段2.3 嵌入式文档数组字段2.4 嵌入式文档数组字段 1. $eq 比较查询操作符 $eq 操作符匹配字段值等于指定值的文档。 db.c… 文章目录 1. $eq 比较查询操作符1.1 基本类型字段1.2 嵌入式文档字段1.3 数组字段 2. $eleMatch 数组查询操作符2.1 基本类型数组字段2.2 基本类型数组字段2.3 嵌入式文档数组字段2.4 嵌入式文档数组字段 1. $eq 比较查询操作符 $eq 操作符匹配字段值等于指定值的文档。 db.colletion.find({{ field: { $eq: value } } })$eq 运算符等同于下面的形式但 value 是正则表达式的情况除外。 db.colletion.find({{ field: value } })1.1 基本类型字段 构造测试数据 db.inventory.drop()db.inventory.insertMany( [{ _id: 1, item: { name: ab, code: 123 }, qty: 15, tags: [ A, B, C ] },{ _id: 2, item: { name: cd, code: 123 }, qty: 20, tags: [ B ] },{ _id: 3, item: { name: ij, code: 456 }, qty: 25, tags: [ A, B ] },{ _id: 4, item: { name: xy, code: 456 }, qty: 30, tags: [ B, A ] },{ _id: 5, item: { name: mn, code: 000 }, qty: 20, tags: [ [ A, B ], C ] } ] )查询 qty20 的所有文档 db.inventory.find({qty: {$eq: 20} })db.inventory.find({qty: 20 })// 1 {_id: 2,item: {name: cd,code: 123},qty: 20,tags: [B] }// 2 {_id: 5,item: {name: mn,code: 000},qty: 20,tags: [[A,B],C] }Document(collection inventory) Data public class Inventory {Idprivate int id;private Item item;private int qty;private ListObject tags;Datapublic static class Item {private String name;private String code;} }Test public void queryTest() {//构造查询条件Query query new Query();query.addCriteria(Criteria.where(qty).is(20));//执行查询 ListInventory inventoryList mongoTemplate.find(query, Inventory.class);inventoryList.forEach(System.out::println);//Inventory(id2, itemInventory.Item(namecd, code123), qty20, tags[B])//Inventory(id5, itemInventory.Item(namemn, code000), qty20, tags[[A, B], C]) }1.2 嵌入式文档字段 构造测试数据 db.inventory.drop()db.inventory.insertMany( [{ _id: 1, item: { name: ab, code: 123 }, qty: 15, tags: [ A, B, C ] },{ _id: 2, item: { name: cd, code: 123 }, qty: 20, tags: [ B ] },{ _id: 3, item: { name: ij, code: 456 }, qty: 25, tags: [ A, B ] },{ _id: 4, item: { name: xy, code: 456 }, qty: 30, tags: [ B, A ] },{ _id: 5, item: { name: mn, code: 000 }, qty: 20, tags: [ [ A, B ], C ] } ] )查询 “item.name”“ab” 的所有文档 db.inventory.find({item.name: {$eq: ab} })db.inventory.find({item.name: ab })// 1 {_id: 1,item: {name: ab,code: 123},qty: 15,tags: [A,B,C] }Test public void queryTest() {//构造查询条件Query query new Query();query.addCriteria(Criteria.where(item.name).is(ab));//执行查询ListInventory inventoryList mongoTemplate.find(query, Inventory.class);inventoryList.forEach(System.out::println);//Inventory(id1, itemInventory.Item(nameab, code123), qty15, tags[A, B, C]) }1.3 数组字段 构造测试数据 db.inventory.drop()db.inventory.insertMany([{ _id : 1, item : abc1, description: product 1, qty: 300 },{ _id : 2, item : abc2, description: product 2, qty: 200 },{ _id : 3, item : xyz1, description: product 3, qty: 250 },{ _id : 4, item : VWZ1, description: product 4, qty: 300 },{ _id : 5, item : VWZ2, description: product 5, qty: 180 } ])查询 tags 数组包含 “A” 的所有文档 db.inventory.find({tags: {$eq: A} })db.inventory.find({tags: A })// 1 {_id: 1,item: {name: ab,code: 123},qty: 15,tags: [A,B,C] }// 2 {_id: 3,item: {name: ij,code: 456},qty: 25,tags: [A,B] }// 3 {_id: 4,item: {name: xy,code: 456},qty: 30,tags: [B,A] }Test public void queryTest() {//构造查询条件Query query new Query();query.addCriteria(Criteria.where(tags).is(A));//执行查询ListInventory inventoryList mongoTemplate.find(query, Inventory.class);//打印inventoryList.forEach(System.out::println);//Inventory(id1, itemInventory.Item(nameab, code123), qty15, tags[A, B, C])//Inventory(id3, itemInventory.Item(nameij, code456), qty25, tags[A, B])//Inventory(id4, itemInventory.Item(namexy, code456), qty30, tags[B, A]) }2. $eleMatch 数组查询操作符 $elemMatch 操作符匹配包含数组字段的文档该字段至少有一个元素与所有指定的查询条件匹配。 db.collection.find({ arrayField: { $elemMatch: { condition1, condition2 } } })2.1 基本类型数组字段 构造测试数据 db.student.drop()db.student.insertMany([{ _id: 1, scores: [ 82, 85, 88 ] },{ _id: 2, scorse: [ 75, 88, 89 ] } ])查询 scores 数组中至少包含一个大于等于80并且小于85的文档 db.student.find({ scores: { $elemMatch: { $gte: 80, $lt: 85 } } })// 1 {_id: 1,scores: [82,85,88] }Data Document(collection students) public class Student {Idprivate int id;private ListInteger scores; }Test public void queryTest() {// 构建查询条件Query query new Query();Criteria criteria Criteria.where(scores).elemMatch(Criteria.where($gte).is(80).and($lt).is(85));query.addCriteria(criteria);// 执行查询ListStudent student mongoTemplate.find(query, Student.class, student);student.forEach(System.out::println);//Student(id1, scores[82, 85, 88]) }2.2 基本类型数组字段 构造测试数据 db.user.drop()db.user.insertMany([{ name: Alice, age: 25, email: aliceexample.com, hobbies: [reading, writing, music] },{ name: John, age: 30, email: Johnqq.com, hobbies: [reading, gaming, traveling] },{ name: Jane, age: 25, email: Janeqq.com, hobbies: [sports, music, cooking] },{ name: Mike, age: 35, email: Mikeqq.com, hobbies: [reading, writing, painting] } ]) 查询age30 并且 hobbies 数组中包含 reading 的文档 db.student.find({ age: { $gte: 30 }, hobbies: { $elemMatch: { $eq: reading } } })// 1 {_id: ObjectId(66a4ab82f074c9a04808d562),name: John,age: 30,email: Johnqq.com,hobbies: [reading,gaming,traveling] }// 2 {_id: ObjectId(66a4ab82f074c9a04808d564),name: Mike,age: 35,email: Mikeqq.com,hobbies: [reading,writing,painting] }Data Document(collection user) public class User {Idprivate String id;private String name;private Integer age;private String email;private ListString hobbies;public User(String name,Integer age,String email,ListString hobbies){this.name name;this.age age;this.email email;this.hobbies hobbies;} }Test public void queryTest() {// 构建查询条件Query query new Query();Criteria criteria Criteria.where(age).gte(30).and(hobbies).elemMatch(Criteria.where($eq).is(reading));query.addCriteria(criteria);// 执行查询ListUser userList mongoTemplate.find(query, User.class, user);userList.forEach(System.out::println);//User(id66a4ab82f074c9a04808d562, nameJohn, age30, emailJohnqq.com, hobbies[reading, gaming, traveling])//User(id66a4ab82f074c9a04808d564, nameMike, age35, emailMikeqq.com, hobbies[reading, writing, painting]) }2.3 嵌入式文档数组字段 构造测试数据 db.survey.drop()db.survey.insertMany( [{ _id: 1, results: [ { product: abc, score: 10 },{ product: xyz, score: 5 } ] },{ _id: 2, results: [ { product: abc, score: 8 },{ product: xyz, score: 7 } ] },{ _id: 3, results: [ { product: abc, score: 7 },{ product: xyz, score: 8 } ] },{ _id: 4, results: [ { product: abc, score: 7 },{ product: def, score: 8 } ] },{ _id: 5, results: { product: xyz, score: 9 } } ] )查询 results 数组中 product“def” 的文档 db.survey.find({ results: { $elemMatch: { product: def } } })db.survey.find({ results.product: def } )// 1 {_id: 4,results: [{product: abc,score: 7},{product: def,score: 8}] }Data Document(collection survey) public class Survey {Idprivate int id;private ListResult results;Datapublic class Result {private String item;private int score;} }Test public void queryTest() {// 构建查询条件Query query new Query();Criteria criteria Criteria.where(results).elemMatch(Criteria.where(product).is(def));query.addCriteria(criteria);// 执行查询ListSurvey surveys mongoTemplate.find(query, Survey.class);surveys.forEach(System.out::println);//Survey(id4, results[Survey.Result(itemnull, score7), Survey.Result(itemnull, score8)]) }2.4 嵌入式文档数组字段 查询 results 数组中 productxyzscore8 的文档 db.survey.find({ results: { $elemMatch: { product: xyz, score: { $gte: 8 } } } })// 1 {_id: 3,results: [{product: abc,score: 7},{product: xyz,score: 8}] }Test public void queryTest() {// 构建查询条件Query query new Query();Criteria criteria Criteria.where(results).elemMatch(Criteria.where(product).is(xyz).and(score).gte(8));query.addCriteria(criteria);// 执行查询ListSurvey surveys mongoTemplate.find(query, Survey.class);surveys.forEach(System.out::println);//Survey(id3, results[Survey.Result(itemnull, score7), Survey.Result(itemnull, score8)]) }
http://www.zqtcl.cn/news/486299/

相关文章:

  • 湖州医院网站建设方案网页游戏知乎
  • 以网站建设为开题报告临海门户网站住房和城乡建设规划局
  • 河南省大型项目建设办公室网站wordpress置顶功能
  • 奉化网站建设三合一网站建设多少钱
  • wordpress文章页怎么调用网站图片wordpress菜单锚点定位
  • 网站建设运营合作合同网站建设英文合同
  • wordpress chrome插件开发图片式网站利于做优化吗
  • 如何做好品牌网站建设策划app要有网站做基础
  • 横沥网站建设公司wordpress运行php
  • 南皮网站建设价格网络推广这个工作好做吗
  • 长安大学门户网站是谁给做的网站排名logo怎么做
  • 襄樊做网站做网站做网站
  • 百度做网站续费费用网站开发的可行性
  • 电子商务网站建设效益分析如何才能做好品牌网站建设策划
  • 能打开各种网站的浏览器app文章目录wordpress
  • 网站注册页面html中国建设招标网网站
  • 云南网站设计海外直购网站建设方案书范文
  • 网站视频小程序商城多少钱
  • 美耐皿 技术支持 东莞网站建设如何将网站指向404
  • 如何做网站的维护和推广wordpress首页在哪里修改
  • 网站建设公司在哪里宣传网站群系统建设的目的
  • 建立网站的教学书籍最新网站建设哪家公司好
  • 视频网站开发者工具科技网站新版网站上线
  • 网站设计简单网页百度提交网站
  • 建设企业网站网站崩溃西安百度网站快速排名
  • 前端 国外 网站请人做网站得多少钱
  • 微商如何做网站引流上海市有哪些公司
  • 服务类型网站开发需要哪些技术中国设计师网效果图
  • 电子商务网站建设技术有哪些方面做婚礼请柬的网站有哪些
  • 做暖暖欧美网站全国职工素质建设工程专题网站