小编nwk*_*ley的帖子

Mongoose/mongoDB查询加入..但我来自sql背景

我来自一个sql背景,所以在我连接表的sql中编写查询非常简单,但我想我在mongoose/mongodb中遗漏了

基本上我知道Subscriber_ID(映射到User Collection中的文档)

我想拉动项目组,包含用户所属的所有项目,所以如果我在pseduo sql中写这个,那就像

Select 
  ProjectGroup.title, 
  Project.Title 
FROM 
  ProjectGroup, 
  Project, 
  User 
WHERE 
  User.id = req.body.subscriber_id 
  AND Project.subscriber_id = User.id 
  AND  ProjectGroup.project_id = Project.id
Run Code Online (Sandbox Code Playgroud)

必须有一种方法可以在mongoose/mongodb中进行类似的连接,因为类型正在映射到模式吗?

我的架构.....

项目组架构

var ProjectGroupSchema = new Schema({
    title             : String
  , projects          : [ { type: Schema.Types.ObjectId, ref: 'Project' } ]
});
Run Code Online (Sandbox Code Playgroud)

项目架构

var ProjectSchema = new Schema({
    title         : {type : String, default : '', required : true}
  , subscribers   : [{ type: Schema.Types.ObjectId, ref: 'User' }]
});
Run Code Online (Sandbox Code Playgroud)

用户架构

var UserSchema = new Schema({ …
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js

22
推荐指数
1
解决办法
4万
查看次数

如何使用node.js superagent发布multipart/form-data

我试图将我的superagent post请求中的内容类型发送到multipart/form-data.

var myagent = superagent.agent();

myagent
  .post('http://localhost/endpoint')
  .set('api_key', apikey)
  .set('Content-Type', 'multipart/form-data')
  .send(fields)
  .end(function(error, response){
    if(error) { 
       console.log("Error: " + error);
    }
  });
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:TypeError:参数必须是一个字符串

如果我删除:

.set('Content-Type', 'multipart/form-data')
Run Code Online (Sandbox Code Playgroud)

我没有得到任何错误,但我的后端正在接收内容类型的请求:application/json

如何强制内容类型为multipart/form-data,以便我可以访问req.files()?

node.js superagent

21
推荐指数
3
解决办法
3万
查看次数

使用godaddy gd_bundle.crt运行SSL node.js服务器

我无法让我的SSL服务器使用来自godaddy的证书

使用Express:3.1.0

下面是一个在本地生成/没有由go daddy签名的密钥/ crt(浏览器抱怨,但如果你添加异常,它可以工作.

var http = require('https');    
var privateKey  = fs.readFileSync('/var/www/dev/ssl/server.key').toString();
    var certificate = fs.readFileSync('/var/www/dev/ssl/server.crt').toString();
    var credentials = {key: privateKey, cert: certificate};
    var https = http.createServer(credentials, app);
Run Code Online (Sandbox Code Playgroud)

有了godaddy我提供了一个额外的文件gd_bundle.crt我相信你这样实现,但是我收到一个错误

var http = require('https');
    var privateKey  = fs.readFileSync('/var/www/prod/ssl/mysite.key').toString();
    var certificate = fs.readFileSync('/var/www/prod/ssl/mysite.com.crt').toString();
    var ca = fs.readFileSync('/var/www/prod/ssl/gd_bundle.crt').toString();
    var credentials = {key: privateKey, cert: certificate, ca: ca};
    var https = http.createServer(credentials, app);
Run Code Online (Sandbox Code Playgroud)

使用此配置,我得到:错误107(net :: ERR_SSL_PROTOCOL_ERROR):SSL协议错误.

真相被告知我没有创建他们的密钥/证书我们的devops家伙...我不知道如果我正在实施godaddy那些错误或如果有一种方法来确保他正确设置密钥/ crt文件我可以解决....

有谁看到明显错误的任何明显错误?

ssl https x509 node.js

18
推荐指数
2
解决办法
1万
查看次数

访问_cachedSystemAnimationFence的NSInternalInconsistencyException需要主线程

对一些beta测试者使用Crittercism我看到一个错误出现了几次,我从来没有经历过我自己,我无法复制.

Crittercism告诉我:访问_cachedSystemAnimationFence的NSInternalInconsistencyException需要主线程

它指向的线是:

[picker dismissViewControllerAnimated:YES completion:^{
Run Code Online (Sandbox Code Playgroud)

在StackOverflow上做一些阅读似乎应该在主线程上运行任何UI代码.我遇到的错误是因为dismissViewControllerAnimated已经在后台线程上运行了吗?

好奇为什么这个错误是相对随机的(即我不能重现它)以及我该如何解决它.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    __block PHObjectPlaceholder *assetPlaceholder;

    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{

        PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:[info objectForKey:@"UIImagePickerControllerOriginalImage"]];

        assetPlaceholder = changeRequest.placeholderForCreatedAsset;

    } completionHandler:^(BOOL success, NSError *error) {

        NSArray *photos = [[NSArray alloc] initWithObjects:assetPlaceholder.localIdentifier, nil];
        PHFetchResult *savedPhotos = [PHAsset fetchAssetsWithLocalIdentifiers:photos options:nil];

        [savedPhotos enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {

            NSMutableArray *images = self.event.eventAttachments;
            if (images) {
                [images addObject:asset];
            } else {
                images = [[NSMutableArray alloc]init];
                [images addObject:asset];
            }

            self.event.eventAttachments = images;

            [picker dismissViewControllerAnimated:YES …
Run Code Online (Sandbox Code Playgroud)

ios

13
推荐指数
2
解决办法
1万
查看次数

需要减少expressjs中路由的超时时间

在expressjs中有一种方法可以设置每条路线的超时限制.

我有一些路线可能需要30-45秒来处理(大量的任务)

然后其他路线,如果需要超过5秒,我希望它超时.

我想我问有没有办法全局设置请求的超时限制,有没有办法在路由上单独执行.

timeout node.js express

8
推荐指数
1
解决办法
2828
查看次数

如何使用 JSON Schema 有条件地指定默认值

我有外地身份

如果用户将作业设置为草稿状态,我不想要求描述字段 - 但我确实希望有一个默认的空字符串。

如果用户正在发布作业,那么我希望需要描述。

我无法弄清楚如何在“oneOf -草案”数组中设置描述的默认值。

这是我的架构

{
  "schema": "http://json-schema.org/draft-04/schema#",
  "$id": "http://company.com/schemas/job-update.json#",
  "title": "Job",
  "description": "Update job",
  "type": "object",
  "properties": {
    "title": { 
      "type": "string",
      "minLength": 2
    },
    "description": { 
      "type": "string"
     // Can't set default here - as it will apply for the publish status.
    },    
    "status": { 
      "enum": ["draft", "published", "onhold"],
      "default": "draft"
    }
  },
  "oneOf": [
        {
          "description": "Draft jobs do not require any validation",
          "properties": {
            "status": { "enum": ["draft"]}
          },
          "required": …
Run Code Online (Sandbox Code Playgroud)

jsonschema json-schema-validator json-schema-defaults

8
推荐指数
1
解决办法
2万
查看次数

node jitsu找不到本地模块

我有一个成功在本地工作的应用程序,所以我知道代码工作.但是,当我去部署到节点jitsu时,我收到一个错误,它无法找到本地模块.这是我有的:

文件设置:

/index.js
/config/config.js
Run Code Online (Sandbox Code Playgroud)

index.js

var cfg = require('./config/config.js');
Run Code Online (Sandbox Code Playgroud)

尝试部署节点jitsu时给我一个错误:

Error: Cannot find module './config/config.js'
Run Code Online (Sandbox Code Playgroud)

由于所有这些代码都在本地工作,我不相信这是一个编码问题.我的印象是本地模块不需要包含在package.json中,但也许它们可以用于节点jitsu?我阅读了他们的文档,但找不到本地模块的任何特殊内容.

谢谢!

node.js nodejitsu

5
推荐指数
1
解决办法
2565
查看次数

PHImageManager返回的图像在设备上的方向不正确

我为用户提供了从他们的相机胶卷中挑选照片并上传到服务器的能力。

方向在相机胶卷中显示正确。

当我使用模拟器(iphone5,iphone6等)时,一切正常,并且上传到服务器时照片的方向正确。

当我连接设备并选择照片时,图像始终朝向90 CCW。如果我在保存结果之前注销image.imageOrientation,我可以看到它的'3'表示UIImageOrientationRight。

有谁知道为什么在设备上其90 CCW和模拟器正确?

这是我的代码:

(event.eventAttachments是PHAssets的数组)

__block NSMutableArray *images = [[NSMutableArray alloc] init];

PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
options.networkAccessAllowed = YES;
options.synchronous = YES;

for(id asset in event.eventAttachments) {
  CGFloat scale = [UIScreen mainScreen].scale;
  CGSize targetSize = CGSizeMake(CGRectGetWidth([UIScreen mainScreen].bounds) * scale, CGRectGetHeight([UIScreen mainScreen].bounds) * scale);
  [[PHImageManager defaultManager] requestImageForAsset:asset
    targetSize:targetSize
    contentMode:PHImageContentModeAspectFit
    options:options
    resultHandler:^(UIImage *result, NSDictionary *info) {
    if (result) {
      NSMutableDictionary *imageDict = [[NSMutableDictionary alloc] init];
      [imageDict setObject:result forKey:@"image"];
      [imageDict setObject:[NSString stringWithFormat:@"image.jpg"] forKey:@"name"];
      [images addObject: imageDict];
    } …
Run Code Online (Sandbox Code Playgroud)

ios xcode6 ios8

5
推荐指数
1
解决办法
1391
查看次数

使用 .each 和最接近的()

我试图遍历表单中的一堆字段,需要更改链接文本。

我想要的结果是

Alert("Second 1");
Alert("Second 2");
Run Code Online (Sandbox Code Playgroud)

示例代码:

<div class="text-wrapper">
    <input class="field-text" value="">
</div>
<div>
    <ul>
        <li><a href="" class="first">First</li>
        <li><a href="" class="second">Second 1</li>
    </ul>
</div>
<div class="text-wrapper">
    <input class="field-text" value="">
</div>
<div>
    <ul>
        <li><a href="" class="first">First</li>
        <li><a href="" class="second">Second 2</li>
    </ul>
</div>

<script>
jQuery(document).ready(function() {
        jQuery(".text-wrapper").each(function(){
            var value = jQuery(this).closest("a.second").text();
            alert(value);
        });
});
</script>
Run Code Online (Sandbox Code Playgroud)

each jquery

3
推荐指数
1
解决办法
4975
查看次数

如何知道 Node.js 模块中有哪些功能可用

例如,当我下载第三方模块时:

npm install twitter
Run Code Online (Sandbox Code Playgroud)

创建对象时如何知道哪些函数/方法可用。例子:

var twitter = require('twitter');
Run Code Online (Sandbox Code Playgroud)

这也适用于您在 Node.js 中常见的“hello world webserver”

var http = require('http');

var server = http.createServer(function(req, res) {
  res.writeHead(200);
  res.end('Hello Http');
});
server.listen(8080);
Run Code Online (Sandbox Code Playgroud)

我可以在 http 模块上运行一些命令来获取函数/方法列表,例如 .createServer()

我可以挖掘有关特定模块的在线文档,但希望有一种命令行方式可以简单地检索可用函数/方法的列表

顺便说一句...在node.js 中他们怎么称呼它们?函数还是方法?

node.js

2
推荐指数
1
解决办法
1675
查看次数