小编Dmi*_*lov的帖子

MongoDB - 基于另一个字段值的 $match

我想从 SQL 中获得类似简单内部联接的结果,以获得相同 id_customer 的所有帐户。我几乎这样做了,但是我得到了像左连接这样的东西,而且我现在不知道如何过滤查询结果。

询问:

db.customer.aggregate([
    {
        $match: {
            "LOAN.AMOUNT": { $gte: 41000 }
        }
    },

    {
        $lookup: {
            from: "department",
            localField: "ID",
            foreignField: "ACCOUNT.ID_CUSTOMER",
            as: "customer"
        }
    },
    { $match: { "myArray": { $ne: [] } } },
    {
        $unwind: {
            path: "$customer",
            preserveNullAndEmptyArrays: false
        }
    }
    ,
    {
        $unwind: "$customer.ACCOUNT"
    },
    {
            $match: {
                "customer.ACCOUNT.ID_CUSTOMER": "$ID" 
            }
    },

]) 
Run Code Online (Sandbox Code Playgroud)

实际结果:

empty
Run Code Online (Sandbox Code Playgroud)

预期结果:

{ 
    "_id" : ObjectId("5dfccc28d29876c2988c7c05"), 
    "ID" : 4.0, 
    "SECOND_NAME" : "abc", 
    "FIRST_NAME" : "abc", 
    "ID_DISCOUNT" : …
Run Code Online (Sandbox Code Playgroud)

mongodb mongodb-query aggregation-framework

6
推荐指数
1
解决办法
414
查看次数

简单的Oracle存储过程

我有这个SQL查询:

select title
from DEPARTMENT;
Run Code Online (Sandbox Code Playgroud)

我试图编写一个存储过程:

create PROCEDURE select_some
(whats VARCHAR2 ,c_select_some OUT SYS_REFCURSOR) 
AS 
BEGIN 
OPEN c_select_some FOR
SELECT whats
FROM department;
END select_some;
/
Run Code Online (Sandbox Code Playgroud)

但是,在我使用“ title”参数执行它的地方,我得到了8行“ title”而不是实际内容。怎么了?

执行:

var whats varchar2(20)
variable whats = 'Title'
variable mycursor refcursor;

exec select_some (:whats, mycursor);
Run Code Online (Sandbox Code Playgroud)

oracle plsql stored-procedures

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

Flutter - 如何在加载共享首选项时暂停应用程序?

我使用从 InitState() 调用的方法,在那里用 await 加载 SP。但是 Widget 在加载 SP 之前正在构建并且具有空的 SP 值。

void getSP() async {
    var prefs = await SharedPreferences.getInstance();
    _todoItems = prefs.getStringList("key") ?? _todoItems;
  }
Run Code Online (Sandbox Code Playgroud)

完整代码:https : //pastebin.com/EnxfKgPH

dart flutter

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

如何正确使用互斥锁?

我有 mailBox 类,在线程和线程之间共享发送和接收方法:线程 1 发送消息,线程 2 和 3 接收消息,我必须如何使用互斥锁来同步它?

我尝试过的任何组合都没有成功。

std::mutex g_lock; //in global
void sendMessage(Message msg) {
    if (g_lock.try_lock()) {
        this_thread::sleep_for(100ms); // DELAY
        messages->push_back(msg);
        g_lock.unlock();
    }
}
Run Code Online (Sandbox Code Playgroud)

Receive方法相同

完整代码:https : //pastebin.com/7y2RC5br

此代码也无法调试,因为延迟会更改代码的逻辑。

代码的正确逻辑:线程2/3尝试锁定并读取消息,获取空然后解锁线程1尝试锁定并发送消息然后解锁线程2/3尝试锁定并读取消息,获取消息并写入文件然后解锁

当我从线程 2/3 尝试互斥锁的 try_lock 时,我一直在不断阻塞线程,并且线程 1 在所有线程 2/3 之后一直在工作。

c++ mutex std

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

提高python算法的速度

我使用 Twitter 的 Sentiment140 数据集进行情感分析

代码:

从推文中获取文字:

tweet_tokens = []
[tweet_tokens.append(dev.get_tweet_tokens(idx)) for idx, item in enumerate(dev)]
Run Code Online (Sandbox Code Playgroud)

从 token 中获取未知单词

words_without_embs = []
[[words_without_embs.append(w) for w in tweet if w not in word2vec] for tweet in tweet_tokens]
len(words_without_embs)
Run Code Online (Sandbox Code Playgroud)

代码的最后一部分,计算向量作为左右单词(上下文)的平均值

vectors = {} # alg
for word in words_without_embs:
  mean_vectors = []
  for tweet in tweet_tokens:
    if word in tweet:
      idx = tweet.index(word)
      try:
        mean_vector = np.mean([word2vec.get_vector(tweet[idx-1]), word2vec.get_vector(tweet[idx+1])], axis=0)
        mean_vectors.append(mean_vector)
      except:
        pass

    if tweet == tweet_tokens[-1]: # last iteration
      mean_vector_all_tweets = np.mean(mean_vectors, …
Run Code Online (Sandbox Code Playgroud)

python algorithm nlp machine-learning word2vec

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

NodeJS - 强大的 200 MB 文件限制和崩溃

我有 nodejs 服务器:

var http = require('http');
var formidable = require('formidable');
var fs = require('fs');
http.createServer(function (req, res) {
  if (req.url == '/fileupload') {
    console.log(req.rawHeaders)
    var form = new formidable.IncomingForm();
    form.parse(req, function (err, fields, files) {
      if (err) throw err;
      var oldpath = files.file.path
      var newpath = 'C:/VSI/' + files.file.name;
      fs.rename(oldpath, newpath, function (err) {
        //if (err) throw err;
        //res.write('File uploaded and moved!');
        if (err) {
          res.write(JSON.stringify({
            success: false,
            message: 'error happend'
          })
          );
          res.end()
          throw err;
        }

        res.write(JSON.stringify({
          success: …
Run Code Online (Sandbox Code Playgroud)

networking node.js formidable retrofit2

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