从数据库中选择特定字段 [英] Select specific fields from database

查看:48
本文介绍了从数据库中选择特定字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道是否可以使用水线选择特定字段,下面给出了orientdb查询.

I just want to know that is it possible to select specific fields using waterline, orientdb query is given below.

e.g. 
select phone from user

我想使用此查询从用户顶点中选择手机

I want to select phone from user vertices by using this query

userModel.find(phone)
.then(function(phonelist){ 
  if(!phonelist) 
     console.log('msg: RECORD_NOT_FOUND'); 
  else 
     console.log(phonelist);
.catch(function(err){ console.log('err: 'err'); });

推荐答案

是的,这是可能的,例如,您只需要将 select 添加到您的搜索条件中(假设您正在搜索记录id 为 1):

Yes, it's possible, you just need to add select to your search criteria, for example (assuming you are searching for a records with id 1):

userModel.find({ select: ['phone'], id: 1 })

或者:

userModel.find({ select: ['phone'], where: { id: 1 } })

或者如果您想要所有记录,则无需提供条件:

or if you want all records, you don't need to supply criteria:

userModel.find({ select: ['phone'] })

这似乎没有记录在任何地方,但它应该.在 0.11 版本中,还可以通过执行 model.pick('name', 'age') 来定义选择:https://github.com/balderdashy/waterline/pull/952

This doesn't seem to be documented anywhere but it should. In version 0.11 it will also possible to define select by doing model.pick('name', 'age'): https://github.com/balderdashy/waterline/pull/952

这篇关于从数据库中选择特定字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆