使用数组

时间:2015-10-20 21:23:36

标签: mongodb

我有2个集合:我正在尝试加入的用户和网络:

users has user_id, user_name (example: 101, Bob 102, Alice, 103, Charlie)    
network has user_id1, user_id2 (example 101, 103)    

从概念上讲,Charlie(103)在Twitter上关注Bob(101)。 (爱丽丝也有粉丝,但她不喜欢谈论它们。)

这个mongo代码在mongo shell中工作(显示的是user_id):

db.users.find( { user_id : { $in: [53760842,64188597,140479494] } } , { user_name: 1 } )  

{“user_name”:“lizgaule”} {“user_name”:“taella”}

这不是:

var cur = db.network.find( {user_id1 : 14230524}, {_id:0, user_id2:1} )  
var arr = cur.toArray();  
db.users.find( { user_id: { $in: arr } } , { user_name: 1 } )  

我怀疑阵列arr的格式不正确。它包含:         {
                “user_id2”:64188597
        },
        {
                “user_id2”:53760842
        }

问题我需要哪些代码才能使其正常工作?

1 个答案:

答案 0 :(得分:0)

您需要.map()第一次查询的结果。这可用于提取相关值。在你的情况下,我相信var arr = db.network.find( {user_id1 : 14230524}, {_id:0, user_id2:1} ).map(function(doc){ return doc.user_id2; }) ; db.users.find( { user_id: { $in: arr } } , { user_name: 1 } );

.data
     prompt: .asciiz "Enter the max number: "
     message: .asciiz "\nYour max number is: "
     picksPrompt: .asciiz "Enter your amount of picks: "
     picksMessage: .asciiz "\nYour number of picks number is: "
     finalOdds: .asciiz "Your odds are: "

.text
    # prompt the use to enter max number 
    li $v0, 4
    la  $a0, prompt
    syscall


    # get integer from the keyboard
    li, $v0, 5
    syscall


    #store the max in $t0 (ie. 59 balls)
    move $t0, $v0

    # prompt the user to enter number of picks 
    li $v0, 4
    la  $a0, picksPrompt
    syscall


    # get integer from the keyboard
    li, $v0, 5
    syscall

    #store the number of picks in $t1 (ie 3 picks)
    move $t1, $v0


    # display the max number
    li $v0, 4
    la $a0, message
    syscall


    #print or show the max number
    li $v0, 1
    move $a0, $t0
    syscall

    # display the max number
    li $v0, 4
    la $a0, picksMessage
    syscall


    #print or show the max number
    li $v0, 1
    move $a0, $t1
    syscall

#li $t0 , 59    # values assignment to temporary registers
    #li $t1 , 3

    mtc1 $t0,$f0    # move from int register to float-point register
    cvt.s.w $f0,$f0   #Convert int values to float-point values

        mtc1 $t1,$f1 
        cvt.s.w $f1,$f1 # Convert int values to float-point values

    li $t2 , 1
        li $t3 , 1

    mtc1 $t2, $f2
        cvt.s.w $f2,$f2

    mtc1 $t3, $f3
        cvt.s.w $f3,$f3

    li $t6 , 1
        mtc1 $t6, $f6
        cvt.s.w $f6,$f6

        #Start of the while loop
    li $t5, 0
        mtc1 $t5, $f5
        cvt.s.w $f5,$f5

    while: c.lt.s $f1, $f5  
    bc1f endwhile 
        #checks the intital condition and if it's false jump to endwhile
    div.s $f4,$f2,$f0           # $f4 = $f2/$f0
        mul.s $f3, $f3 ,$f4         # $f3 = $f3 * $f4

        sub.s $f0, $f0, $f6
        sub.s $f1, $f1, $f6

    b while # jump to label while
    endwhile: # your code

    # display the odds
    li $v0, 4
    la $f12, finalOdds
    syscall


    #print or show the odds
    li $v0, 2
    mov.s $f12, $f3   # Move contents of register $f3 to register $f12
    syscall